PHP code example of stolt / json-lines

1. Go to this page and download the library: Download stolt/json-lines library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

stolt / json-lines example snippets


$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);

(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'
]);

$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)

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

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