PHP code example of bzick / jsonor

1. Go to this page and download the library: Download bzick/jsonor 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/ */

    

bzick / jsonor example snippets


use Jsonor\JSON;

    
// returns null if it's valid json, or a ParsingException object.
JSON::lint($json);

// Call getMessage() on the exception object to get
// a well formatted error message error like this

// Parse error on line 2:
// ... "key": "value"    "numbers": [1, 2, 3]
// ----------------------^
// Expected one of: 'EOF', '}', ':', ',', ']'

// Call getDetails() on the exception to get more info.

// returns parsed json, like json_decode() does
$data = JSON::decode($json);
// sets yours callback on changes
$data->onChange(function () {
    // store in DB, e.g.
});
// Use $data as array
$data["d"][1]["name"] = "Banana";
$data["d"][1]["desc"] = "It's fruit";
$data["d"][] = [
    "name" => "Apple"
];

unset($c["d"][1]);

foreach($data as $key => $value) {
    // ...
}