PHP code example of ksmz / json

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

    

ksmz / json example snippets


use ksmz\json\Json;

Json::encode(['foo' => 'bar']);

try {
    Json::encode(...);
} catch (RecursionException $exception) {
    // Specific exception
} catch (JsonException $exception) {
    // All possible exceptions
}

public static $errors = [
    JSON_ERROR_DEPTH                 => DepthException::class,
    JSON_ERROR_STATE_MISMATCH        => InvalidJsonException::class,
    JSON_ERROR_CTRL_CHAR             => ControlCharacterException::class,
    JSON_ERROR_SYNTAX                => SyntaxException::class,
    JSON_ERROR_UTF8                  => Utf8Exception::class,
    JSON_ERROR_UTF16                 => Utf16Exception::class,
    JSON_ERROR_RECURSION             => RecursionException::class,
    JSON_ERROR_INF_OR_NAN            => InfOrNanException::class,
    JSON_ERROR_UNSUPPORTED_TYPE      => UnsupportedTypeException::class,
    JSON_ERROR_INVALID_PROPERTY_NAME => InvalidPropertyNameException::class,
];