PHP code example of mrubiosan / loose-schema-navigator
1. Go to this page and download the library: Download mrubiosan/loose-schema-navigator 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/ */
mrubiosan / loose-schema-navigator example snippets
$data = <<<JSONSTR
{
"foo":"123",
"bar":{
"baz": "true",
"buzz": "{\"abc\":\"xyz\"}"
}
}
JSONSTR;
$nav = new Navigator($data);
$nav->foo->int(); // 123
$nav->foo->string(); // "123"
$nav->missingProp->int(); // 0
$nav->missingProp->int(-1); // -1
$nav->bar->baz->int(); // 1
$nav->bar->baz->bool(); // true
$nav->bar->buzz->string(); // "{"abc":"xyz"}"
$nav->bar->buzz->object(); // {"abc":"xyz"}
$nav->bar->buzz->array(); // ["abc" => "xyz"]
$nav->bar->buzz->abc->string(); // "xyz"