There is no license information available for the latest version (1.0.1) of this package.

An Exception based JSON encoder/decoder.

This package's canonical repository appears to be gone and the package has been frozen as a result.

1.0.1 2017-10-26 14:28 UTC

This package is not auto-updated.

Last update: 2019-04-22 15:46:08 UTC


README

Build Status Latest Stable Version Total Downloads Monthly Downloads Daily Downloads License

Installation

composer install tomwright/json

Usage

Encoding

$json = new \TomWright\JSON\JSON();

try {
    $jsonString = $json->encode([
        'message' => 'This is my value',
    ]);
    echo $jsonString; // String... {"message":"This is my value"}   
} catch (\TomWright\JSON\Exception\JSONEncodeException $e) {
    echo 'Error encoding: ' . $e->getMessage();
}

Decoding

$json = new \TomWright\JSON\JSON();

try {
    $value = $json->decode('{"message":"This is my value"}');
    echo $value; // Object... {"message" => "This is my value"}
} catch (\TomWright\JSON\Exception\JSONDecodeException $e) {
    echo 'Error decoding: ' . $e->getMessage();
}

Exceptions

  • A JSONEncodeException can be thrown when trying to JSON encode a value.
  • A JSONDecodeException can be thrown when trying to JSON decode a string.
  • Both JSONEncodeException and JSONDecodeException extend JSONException.