victorap93 / readjson
Read Json makes it easy to read and work with json files.
Installs: 64
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/victorap93/readjson
Requires
- php: >=5.3.2
README
Read Json makes it easy to read and work with json files.
Installation
The recommended way to install this is through Composer.
composer require victorap93/readjson
How to use
Assuming you have a .json file ./readjson/stores.json with the following content.
{
"stores": [
{
"name": "store one",
"products": [
{
"name": "product one",
"amount": 10
},
{
"name": "product two",
"amount": 20
}
]
},
{
"name": "store two",
"products": [
{
"name": "product two",
"amount": 22
},
{
"name": "product three",
"amount": 33
}
]
}
]
}
And this .php in the same folder ./readjson/index.php, the example below show different ways to acess .json file.
use \victorap93\ReadJson; $json_path = "./stores.json"; // Get all json content. $ReadJson = new ReadJson($json_path); $json_object_value1 = $ReadJson->getJsonObject(); // Accessing the obtained object. $json_object_value2 = $json_object_value1->stores[0]->products; // Get a specified json content position in instance of class. $ReadJson = new ReadJson($json_path, ['stores', 0, 'products']); $json_object_value3 = $ReadJson->getJsonObject(); // Get a specified json content position in method call. $ReadJson = new ReadJson($json_path, ['stores', 0]); $json_object_value4 = $ReadJson->getJsonObject(['products']); // Get a specified json content position with object. $json_object_value5 = $ReadJson->accessRecursiveKeys($json_object_value4, [0, 'name']);
Help and docs
License
Read Json is made available under the MIT License (MIT). Please see License File for more information.