2017 © Pedro Peláez
 

library json

A simple wrapper class to work with json in PHP.

image

yadakhov/json

A simple wrapper class to work with json in PHP.

  • Saturday, December 31, 2016
  • by yadakhov
  • Repository
  • 1 Watchers
  • 18 Stars
  • 2,541 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 3 Forks
  • 0 Open issues
  • 7 Versions
  • 1 % Grown

The README.md

Json

Latest Stable Version License Build Status, (*1)

A simple wrapper class for working with Json., (*2)

Work with json as an object in PHP. Provides a simple api with dot notation for field access., (*3)

Use get() or set() to access any fields in the json structure., (*4)

require __DIR__.'/vendor/autoload.php';
use Yadakhov\Json;

$json = new Json(['status' => 'success', 'developer' => ['name' => 'Yada Khov']]);
echo $json;  // {"status":"success","developer":{"name":"Yada Khov"}}

$json->set('status', 'winning');
echo $json;  // {"status":"winning","developer":{"name":"Yada Khov"}}

Installation

With Composer

$ composer require yadakhov/json

Old fashion php

// download src/Json.php to your code folder..
require_once '/path/to/Json.php';

use Yadakhov/Json;

$json = new Json();

Usage: The Constructor

Will to accept array or json encoded string., (*5)

// There are 2 ways to instantiation a new Json object

// 1.
$json1 = new Json('{"status":"success"}');

// 2
$json2 = new Json(['status' => 'success']);

API functions

$json->get('dot.notation') - get a field
$json->set('dot.notation', $value) - set a field
$json->toString() - return the Json object as a string
$json->toStringDot() - return the dot notation of the structure.
$json->toStringPretty() - json pretty print
$json->toArray() - return the array representation.

Design decision

Internally, the json is stored as a PHP array. This allows us to use dot notation., (*6)

The left hand side of a json encoded string needs to be double quoted., (*7)

{
    "status": "success"
}

Dependencies

PHP 5.4 for short array syntax., (*8)

This package uses illuminate/support for the array and string helpers., (*9)

Run tests

./vendor/bin/phpunit 

The Versions

31/12 2016

dev-master

9999999-dev https://github.com/yadakhov/json

A simple wrapper class to work with json in PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

api json

31/12 2016

v2.0.1

2.0.1.0 https://github.com/yadakhov/json

A simple wrapper class to work with json in PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

api json

31/12 2016

dev-develop

dev-develop https://github.com/yadakhov/json

A simple wrapper class to work with json in PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

api json

31/12 2016

v2.0.0

2.0.0.0 https://github.com/yadakhov/json

A simple wrapper class to work with json in PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

api json

03/08 2016

v1.0.2

1.0.2.0 https://github.com/yadakhov/json

A simple API extension class for Json.

  Sources   Download

MIT

The Requires

 

The Development Requires

api json

13/06 2015

v1.0.1

1.0.1.0 https://github.com/yadakhov/json

A simple API extension class for Json.

  Sources   Download

MIT

The Requires

 

The Development Requires

api json

09/06 2015

v1.0.0

1.0.0.0 https://github.com/yadakhov/json

A simple API extension class for Json.

  Sources   Download

MIT

The Requires

 

The Development Requires

api json