2017 © Pedro Peláez
 

library json-stream

A bundle of tools to work with JSON in PHP

image

bcncommerce/json-stream

A bundle of tools to work with JSON in PHP

  • Wednesday, May 23, 2018
  • by skolodyazhnyy
  • Repository
  • 4 Watchers
  • 31 Stars
  • 139,627 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 10 Forks
  • 6 Open issues
  • 6 Versions
  • 18 % Grown

The README.md

PHP JSON Component

Build Status, (*1)

This project is a rewritten fork of few very nice JSON libs for PHP:, (*2)

JSON Writer

There is an example of product catalog export using JSON Writer, (*3)

$fh = fopen($filename, "w");
$writer = new Writer($fh);

$writer->enter(Writer::TYPE_OBJECT);                // enter root object
    $writer->write("catalog", $catalog['id']);      // write key-value entry
    $writer->enter("items", Writer::TYPE_ARRAY);    // enter items array
        foreach($catalog['products'] as $product) {
            $writer->write(null, array(             // write an array item
                'sku'  => $product['sku'],
                'name' => $product['name']
            ));
        }
    $writer->leave();                               // leave items array
$writer->leave();                                   // leave root object

fclose($fh);

Output, (*4)

{"catalog":19,"items":[{"sku":"0001","name":"Product #1"},{"sku":"0002","name":"Product #2"}]}

JSON Reader

Using JSON Reader you can easily read json generated by code above, (*5)

$fh = fopen($filename, "r");

$reader = new Reader($fh);
$reader->enter(Reader::TYPE_OBJECT);                // enter root object
    $catalog['id'] = $reader->read("catalog");      // read catalog node
    $reader->enter("items", Reader::TYPE_ARRAY);    // enter item array
        while($product = $reader->read()) {         // read product structure
            $catalog['products'][] = $product;
        }
    $reader->leave();                               // leave item node
$reader->leave();                                   // leave root object

fclose($fh);

The Versions

23/05 2018

dev-master

9999999-dev

A bundle of tools to work with JSON in PHP

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

by Sergey Kolodyazhnyy

parser json writer reader streaming

23/05 2018

0.4

0.4.0.0

A bundle of tools to work with JSON in PHP

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

by Sergey Kolodyazhnyy

parser json writer reader streaming

14/10 2016

0.3.1

0.3.1.0

A bundle of tools to work with JSON in PHP

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

by Sergey Kolodyazhnyy

parser json writer reader streaming

28/04 2014

0.3.0

0.3.0.0

A bundle of tools to work with JSON in PHP

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

by Sergey Kolodyazhnyy

parser json writer reader streaming

01/04 2014

0.2.0

0.2.0.0

A bundle of tools to work with JSON in PHP

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

by Sergey Kolodyazhnyy

parser json writer reader streaming

01/04 2014

0.1.0

0.1.0.0

A bundle of tools to work with JSON in PHP

  Sources   Download

MIT

The Requires

  • php >=5.3

 

The Development Requires

by Sergey Kolodyazhnyy

parser json writer reader streaming