Note: All questions and issues please send to https://github.com/railt/railt/issues
Small examples on working with the RFC-7159 specification.
<?php
use Railt\Json\Json;
use Railt\Json\Exception\JsonException;
try {
$json = Json::encode([1, 2, 3]);
} catch (JsonException $exception) {
// Exception handling
}
<?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
}
<?php
use Railt\Json\Json5;
use Railt\Json\Exception\JsonException;
try {
$json = Json5::encode([1, 2, 3]);
} catch (JsonException $exception) {
// Exception handling
}
<?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
}