PHP code example of arturdoruch / json

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

    

arturdoruch / json example snippets


use ArturDoruch\Json\Json;
use ArturDoruch\Json\UnexpectedJsonException;

$jsonString = '';
// Decode JSON to array or stdClass object.
// If JSON is invalid `ArturDoruch\Json\UnexpectedJsonException` is thrown.
$json = new Json($jsonString);

// Get decoded JSON.
$json->getDecoded();

// Get encoded JSON with specified options like JSON_PRETTY_PRINT.
$json->getEncoded();

// Catch decoding exception
try {
    $json = new Json($jsonString);
} catch (UnexpectedJsonException $exception) {
    // Get decoded invalid JSON.
    $exception->getJson();
    // Get error code.
    $exception->getCode();
}

use ArturDoruch\Json\JsonUtils;

// JSON string. 
$json = '{"string": "foo bar \"baz\"", "integer": 128, "float": -1.5678, "boolean": true, "null": null}';
$classPrefix = 'json';
$highlighted = JsonUtils::highlightSyntax($json, $classPrefix);