2017 © Pedro Peláez
 

library json-lines

Library for the JSON Lines text file format.

image

stolt/json-lines

Library for the JSON Lines text file format.

  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 11 Versions
  • 34 % Grown

The README.md

JsonLines

Test Version PHP Version, (*1)

This is a library to enline to the JSON Lines format and to deline back from it to JSON., (*2)

Installation via Composer

``` bash composer require stolt/json-lines, (*3)


#### Usage To __enline__ a data structure into JSON Lines use the `enline` method. ```php $jsonLines = (new JsonLines())->enline([ ["one" => 1, "two" => 2], ["three" => 3, "four" => 4, "five" => 5], ["six" => 6, "seven" => 7, "key" => "value"], ["nested" => ["a", "b", "c"]], ]); var_dump($jsonLines);

Which will give you the following JSON Lines string., (*4)

string(107) "{"one":1,"two":2}
{"three":3,"four":4,"five":5}
{"six":6,"seven":7,"key":"value"}
{"nested":["a","b","c"]}
"

To enline a data structure into a JSON Lines file use the enlineToFile method, adding the gz extension will gzip compress the JSON Lines as shown next., (*5)

(new JsonLines())->enlineToFile([
    ["one" => 1, "two" => 2],
    ["three" => 3, "four" => 4, "five" => 5],
    ["six" => 6, "seven" => 7, "key" => "value"],
    ["nested" => ["a", "b", "c"]],
    'out.jsonl.gz'
]);

To deline JSON Lines back into JSON use the deline method., (*6)

$json = (new JsonLines())->deline('{"one":1,"two":2}
{"three":3,"four":4,"five":5}
{"six":6,"seven":7,"key":"value"}
{"nested":["a","b","c"]}'
);
var_dump($json)

Which will give you the following JSON string, which is only beautified here to illustrate the data structure., (*7)

string(287) "[
    {
        "one": 1,
        "two": 2
    },
    {
        "three": 3,
        "four": 4,
        "five": 5
    },
    {
        "six": 6,
        "seven": 7,
        "key": "value"
    },
    {
        "nested": [
            "a",
            "b",
            "c"
        ]
    }
]"

To deline a complete JSON Lines file back into JSON use the delineFromFile method., (*8)

$json = (new JsonLines())->delineFromFile('/path/to/enlined.jsonl');

To deline a complete JSON Lines file line-by-line, use the delineEachLineFromFile method. This allows to iterate over a large file without storing the entire delined file in memory., (*9)

$json_lines = (new JsonLines())->delineEachLineFromFile('/path/to/enlined.jsonl');
foreach ($json_lines as $json_line) {
    var_dump($json_line);
}

Running tests

bash composer test, (*10)

License

This library is licensed under the MIT license. Please see LICENSE for more details., (*11)

Changelog

Please see CHANGELOG for more details., (*12)

Contributing

Please see CONTRIBUTING for more details., (*13)

The Versions

29/01 2018

dev-master

9999999-dev

Library for the JSON Lines text file format.

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

json jsonlines

07/10 2016

v2.0.0

2.0.0.0

Library for the JSON Lines text file format

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

json jsonlines

23/09 2016

v1.0.0

1.0.0.0

Library for the JSON Lines text file format

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

json jsonlines

02/04 2016

v0.2.1

0.2.1.0

Library for the JSON Lines text file format

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

json jsonlines

06/03 2016

v0.2.0

0.2.0.0

Library for the JSON Lines text file format

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

json jsonlines

29/02 2016

v0.1.0

0.1.0.0

Library for the JSON Lines text file format

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

json jsonlines

29/02 2016

v0.0.5

0.0.5.0

Library for the JSON Lines text file format

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

json jsonlines

28/02 2016

v0.0.4

0.0.4.0

Library for the JSON Lines text file format

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

json jsonlines

26/02 2016

v0.0.3

0.0.3.0

Library for the JSON Lines text file format

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

json jsonlines

26/02 2016

v0.0.2

0.0.2.0

Library for the JSON Lines text file format

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

json jsonlines

25/02 2016

v0.0.1

0.0.1.0

Library for the JSON Lines text file format

  Sources   Download

MIT

The Requires

  • php >=5.6.16

 

The Development Requires

json jsonlines