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

This package is auto-updated.

Last update: 2020-06-21 16:36:57 UTC


README

Railt

Travis CI 68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f34633736633566303836613731303337376563372f746573745f636f766572616765 68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f34633736633566303836613731303337376563372f6d61696e7461696e6162696c697479

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
}