Skip to content
This repository has been archived by the owner on Nov 15, 2019. It is now read-only.
/ json Public archive

[DEPRECATED] Simple library for working with JSON (RFC 7159) and JSON5 data structures

License

Notifications You must be signed in to change notification settings

railt/json

Repository files navigation

Railt

Travis CI

PHP 7.1+ railt.org Discord Latest Stable Version Total Downloads License MIT

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
}

About

[DEPRECATED] Simple library for working with JSON (RFC 7159) and JSON5 data structures

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages