PHP Classes

File: README.md

Recommend this page to a friend!
  Classes of Rafal Przetakowski  >  JSON Manager  >  README.md  >  Download  
File: README.md
Role: Auxiliary data
Content type: text/markdown
Description: Auxiliary data
Class: JSON Manager
Manipulate data structures loaded from JSON
Author: By
Last change: Readme
Date: 3 years ago
Size: 1,430 bytes
 

Contents

Class file image Download

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']));
For more information send a message to info at phpclasses dot org.