PHP code example of ronolo / json-query

1. Go to this page and download the library: Download ronolo/json-query library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ronolo / json-query example snippets


use RoNoLo\JsonQuery;

$q = JsonQuery::fromFile('data.json'); // or ...
$q = JsonQuery::fromData(['foo' => 1, 'bar' => 2]); // or ...
$q = JsonQuery::fromJson('{"foo": "bernd", "bar": "kitty"}');

$result = $q->query('foo'); // or ...
$result = $q->query('foo.bar'); // or ...
$result = $q->query('foo.2.bar'); // or ...
$result = $q->query('foo.2.bar.0.name'); // or ...
$result = $q->query('foo.bar.name'); // etc.

use RoNoLo\JsonQuery;

$q = JsonQuery::fromFile('data.json');

$result = $q->query('population'); // 80523700
$result = $q->query('bernd'); // ValueNotFound()
$result = $q->query('persons.name'); // ["Karl", "Jenni"]
$result = $q->query('persons.1.name'); // "Jenni"
$result = $q->query('latlng'); // [51, 9]
$result = $q->query('latlng.0'); // 51
$result = $q->query('persons.hobby.type'); // [["Cars", "Planes", "Music"],["Comics","Dancing"]]