PHP Classes

JSON Manager: Manipulate data structures loaded from JSON

Recommend this page to a friend!
  Info   View files View files (10)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
StarStarStarStar 60%Total: 577 This week: 1All time: 5,338 This week: 560Up
Version License PHP version Categories
jsonmanager 1.0.11GNU General Publi...5.5PHP 5, Data types
Description 

Author

This class can manipulate data structures loaded from JSON.

It can load a data structure from a JSON string. It can optionally be turned into a a collection nested structures.

The class can add, change or get an element of the data structure given its path.

The resulting data structure can be saved back to a JSON string.

Picture of Rafal Przetakowski
  Performance   Level  
Name: Rafal Przetakowski <contact>
Classes: 4 packages by
Country: Poland Poland
Age: 45
All time rank: 115528 in Poland Poland
Week rank: 106 Up5 in Poland Poland Up

Details

JsonManager

JsonMaganer helps to manage json data as an object.

With this class you can: - add new field to selected path - set new value of field in selected path - get value of field - get new JsonManager object if value of field is array - use JsonManager in foreach loop

Installation

composer

composer require beeflow/jsonmanager

GIT

Just run

git clone https://github.com/beeflow/JsonManager.git

Example

Simple Json

$jsonData = '{"id": 11111, "field": "field_name", "value": "new value"}';
$json = new JsonManager($jsonData);
$json->add('addNewRootField', 'new value');
$given = $json->get();

Array collection

$arData = [
    ['id' => '1', 'field' => 'field name 1', 'value' => 'value 1'],
    ['id' => '2', 'field' => 'field name 2', 'value' => 'value 2'],
    ['id' => '3', 'field' => 'field name 3', 'value' => 'value 3']
];
$json = new JsonManager($arData, true);

List fields

$arData = [
    ['id' => '1', 'field' => 'field name 1', 'value' => 'value 1'],
    ['id' => '2', 'field' => 'field name 2', 'value' => 'value 2'],
    ['id' => '3', 'field' => 'field name 3', 'value' => 'value 3']
];
$json = new JsonManager($arData, true);
$expected = [
    1 => ['field' => 'field name 1'],
    2 => ['field' => 'field name 2'],
    3 => ['field' => 'field name 3']
];
$this->assertEquals($expected, $json->listAll(['field']));

  Files folder image Files  
File Role Description
Files folder imageTests (2 files, 1 directory)
Accessible without login Plain text file autoload.php Aux. Auxiliary script
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file composer.lock Data Auxiliary data
Plain text file JsonIterator.php Class Class source
Plain text file JsonManager.php Class Class source
Accessible without login Plain text file phpunit.xml.dist Data Auxiliary data
Accessible without login Plain text file README.md Data Auxiliary data

  Files folder image Files  /  Tests  
File Role Description
Files folder imageMock (1 file)
  Accessible without login Plain text file bootstrap.php Aux. Auxiliary script
  Accessible without login Plain text file JsonManagerTest.php Test Unit test script

  Files folder image Files  /  Tests  /  Mock  
File Role Description
  Plain text file SomeClass.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:577
This week:1
All time:5,338
This week:560Up
 User Ratings  
 
 All time
Utility:87%StarStarStarStarStar
Consistency:81%StarStarStarStarStar
Documentation:-
Examples:-
Tests:81%StarStarStarStarStar
Videos:-
Overall:60%StarStarStarStar
Rank:1205