railt / json
This package is abandoned and no longer maintained.
No replacement package was suggested.
Simple library for working with json data
1.4.x-dev
2019-05-21 13:46 UTC
Requires
- php: >=7.1.3
- ext-json: *
- justinrainbow/json-schema: ~5.2
- phplrt/io: ~1.1
- phplrt/lexer: ~1.1
- phplrt/parser: ~1.1
Requires (Dev)
- phplrt/compiler: ~1.0
- phpunit/phpunit: ^7.5
Suggests
- railt/lexer: (1.4.*) JSON5 decoder support
- railt/parser: (1.4.*) JSON5 decoder support
This package is auto-updated.
Last update: 2020-06-21 16:36:57 UTC
README
Json
Note: All questions and issues please send to https://github.com/railt/railt/issues
JSON RFC-7159 Usage
Small examples on working with the RFC-7159 specification.
Encoding
<?php use Railt\Json\Json; use Railt\Json\Exception\JsonException; try { $json = Json::encode([1, 2, 3]); } catch (JsonException $exception) { // Exception handling }
Decoding
<?php use Railt\Json\Json; use Railt\Json\Exception\JsonException; try { $data = Json::decode(<<<'JSON' { "quotes": "I can use \"double quotes\" here", "float": 0.8675309, "number": 42, "array": ["a", "b", "c"] } JSON ); } catch (JsonException $exception) { // Exception handling }
JSON5 Usage
Encoding
<?php use Railt\Json\Json5; use Railt\Json\Exception\JsonException; try { $json = Json5::encode([1, 2, 3]); } catch (JsonException $exception) { // Exception handling }
Decoding
<?php use Railt\Json\Json5; use Railt\Json\Exception\JsonException; try { $data = Json5::decode(<<<'JSON5' // Simple example of JSON5 spec { unquoted: 'and you can quote me on that', singleQuotes: 'I can use "double quotes" here', lineBreaks: "Look, Mom! \ No \\n's!", hexadecimal: 0xDEADBEEF, leadingDecimalPoint: .42, andTrailing: 23., positiveSign: +1, trailingComma: 'in objects', andIn: ['arrays',], "backwardsCompatible": "with JSON", } JSON5 ); } catch (JsonException $exception) { // Exception handling }