PHP code example of johnitvn / json-query
1. Go to this page and download the library: Download johnitvn/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/ */
johnitvn / json-query example snippets
$document = new johnitvn\jsonquery\JsonDocument();
$document->addValue('/path/to/nested/array/-', array('firstName'=> 'Fred', 'lastName' => 'Blogg'));
$json = $document->toJson(true);
$person = $document->getValue('/path/to/nested/array/0');
$document->addValue('/path/to/nested/array/0/lastName', 'Bloggs');
$document->moveValue('/path/to/nested/array/0', '/users/-');
$document->tidy();
$json = $document->toJson(true);
$schema = '{
"items": {
"properties": {
"firstName": {"type": "string"},
"lastName": {"type": "string"}
},
"
$document->loadSchema($schema);
$result = $document->addValue('/-', array('firstName'=> 'Fred', 'lastName' => 'Bloggs'));
# true
$result = $document->addValue('/-', array('firstName'=> 'Fred', 'lastName' => 3));
# false, lastName is not a string
$result = $document->addValue('/0', array('firstName'=> 'Fred'));
# true,
php composer.phar