2017 © Pedro Peláez
 

library plum-json

image

plumphp/plum-json

  • Sunday, October 25, 2015
  • by florianeckerstorfer
  • Repository
  • 1 Watchers
  • 1 Stars
  • 22 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 7 Versions
  • 0 % Grown

The README.md

Plum

PlumJsons includes readers, writers and converters for JSON strings and files. Plum is a data processing pipeline for PHP., (*1)

Build Status Windows Build status Scrutinizer Code Quality Code Coverage StyleCI, (*2)

Developed by Florian Eckerstorfer in Vienna, Europe., (*3)

Features

Readers

  • JsonFileReader reads a .json file from disk and decodes it
  • JsonReader decodes a JSON string

Writers

  • JsonFileWriter encodes an object/array into JSON and saves it to disk
  • JsonWriter encodes an object/array into JSON and returns the string

Converters

  • JsonDecodeConverter takes a JSON string and decodes it
  • JsonEncodeConverter takes an object/array and encodes it to JSON

Installation

You can install Plum using Composer., (*4)

$ composer require plumphp/plum-json

Usage

Please refer to the Plum documentation for more information about Plum in general., (*5)

JsonReader

Plum\PlumJson\JsonReader reads a JSON string. If you want to read a .json file checkout JsonFileReader., (*6)

use Plum\PlumJson\JsonReader;

$reader = new JsonReader('[{'key1': 'value1', 'key2': 'value2'}]');
$reader->getIterator(); // -> \ArrayIterator
$reader->count();

JsonFileReader

Plum\PlumJson\JsonFileReader reads a .json file., (*7)

use Plum\PlumJson\JsonFileReader;

$reader = new JsonFileReader('foo.json');
$reader->getIterator(); // -> \ArrayIterator
$reader->count();

JsonFileWriter

Plum\PlumJson\JsonFileWriter writes the items as JSON into a file., (*8)

use Plum\PlumJson\JsonFileWriter;

$writer = new JsonFileWriter('foobar.json');
$writer->writeItem(['key1' => 'value1', 'key2' => 'value2'));
$writer->finish();

It is essential that finish() is called, because there happens the actual writing. The prepare() method does nothing., (*9)

JsonWriter

Plum\PlumJson\JsonWriter converts the items into JSON format. Please checkout JsonFileWriter if you want to write the JSON into a file., (*10)

use Plum\PlumJson\JsonWriter;

$writer = new JsonWriter();
$writer->writeItem(['key1' => 'value1', 'key2' => 'value2'));
echo $writer->getJson(); // [{'key1': 'value1', 'key2': 'value2'}]

JsonDecodeConverter

Plum\PlumJson\JsonDecodeConverter uses Braincrafted\Json to decode JSON., (*11)

use Plum\PlumJson\JsonDecodeConverter;
use Braincrafted\Json\Json;

$converter = new JsonDecodeConverter(Json::DECODE_ASSOC);
$converter->convert('{"foo": "bar"}'); // -> ['foo' => 'bar']

JsonEncodeConverter

Plum\PlumJson\JsonEncodeConverter uses Braincrafted\Json to encode an object into JSON., (*12)

use Plum\PlumJson\JsonEncodeConverter;

$converter = new JsonEncodeConverter();
$converter->convert(['foo' => 'bar']); // -> '{"foo": "bar"}'

Change Log

Version 0.3 (7 May 2015)

  • Add JsonDecodeConverter
  • Add JsonEncodeConverter

Version 0.2 (22 April 2015)

  • Add support for ReaderFactory

Version 0.1 (17 February 2015)

  • Initial release

License

The MIT license applies to plumphp/plum- json. For the full copyright and license information, please view the LICENSE file distributed with this source code., (*13)

The Versions

25/10 2015

dev-master

9999999-dev

  Sources   Download

MIT

The Requires

 

The Development Requires

json export import plum

07/05 2015

0.3.x-dev

0.3.9999999.9999999-dev

  Sources   Download

The Requires

 

The Development Requires

07/05 2015

v0.3

0.3.0.0

  Sources   Download

The Requires

 

The Development Requires

22/04 2015

0.2.x-dev

0.2.9999999.9999999-dev

  Sources   Download

The Requires

 

The Development Requires

22/04 2015

v0.2

0.2.0.0

  Sources   Download

The Requires

 

The Development Requires

17/02 2015

0.1.x-dev

0.1.9999999.9999999-dev

  Sources   Download

The Requires

 

The Development Requires

17/02 2015

v0.1

0.1.0.0

  Sources   Download

The Requires

 

The Development Requires