PHP Classes
elePHPant
Icontem

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    
Last Updated Ratings Unique User Downloads Download Rankings
2019-06-23 (4 hours ago) RSS 2.0 feedStarStarStarStar 68%Total: 537 All time: 5,468 This week: 456Up
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.

  Performance   Level  
Name: Rafal Przetakowski <contact>
Classes: 4 packages by
Country: Poland Poland

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:537
This week:0
All time:5,468
This week:456Up
 User Ratings  
 
 All time
Utility:100%StarStarStarStarStarStar
Consistency:91%StarStarStarStarStar
Documentation:-
Examples:-
Tests:91%StarStarStarStarStar
Videos:-
Overall:68%StarStarStarStar
Rank:551