2017 © Pedro Peláez
 

library json5

UTF-8 compatible JSON5 parser for PHP

image

colinodell/json5

UTF-8 compatible JSON5 parser for PHP

  • Monday, January 15, 2018
  • by colinodell
  • Repository
  • 6 Watchers
  • 91 Stars
  • 29,344 Installations
  • PHP
  • 3 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 7 Versions
  • 72 % Grown

The README.md

JSON5 for PHP - JSON for Humans

Latest Version on Packagist PHP 8.0+ ![Software License][ico-license] [Build Status][link-build-status] ![Coverage Status][ico-scrutinizer] ![SensioLabs Insight][ico-sensio] UTF-8 Compatible ![Total Downloads][ico-downloads], (*1)

This library is a PHP fork of the JSON5 reference implementation., (*2)

JSON5 is a JS-compatible extension to JSON which allows comments, trailing commas, single-quoted strings, and more:, (*3)

{
    foo: 'bar',
    while: true,

    this: 'is a \
multi-line string',

    // this is an inline comment
    here: 'is another', // inline comment

    /* this is a block comment
       that continues on another line */

    hex: 0xDEADbeef,
    half: .5,
    delta: +10,
    to: Infinity,   // and beyond!

    finally: [
        'some trailing commas',
    ],
}

See the JSON5 website for additional examples and details., (*4)

Install

Via Composer, (*5)

``` bash composer require colinodell/json5, (*6)


## Usage This package adds a `json5_decode()` function which is a drop-in replacement for PHP's built-in `json_decode()`: ``` php $json = file_get_contents('foo.json5'); $data = json5_decode($json);

It takes the same exact parameters in the same order. For more details on these, see the PHP docs., (*7)

To achieve the best possible performance, it'll try parsing with PHP's native function (which usually fails fast) and then falls back to JSON5., (*8)

Exceptions

This function will always throw a SyntaxError exception if parsing fails. This is a subclass of the new \JsonException introduced in PHP 7.3. Providing or omitting the JSON_THROW_ON_ERROR option will have no effect on this behavior., (*9)

Binary / Executable

A binary/executable named json5 is also provided for converting JSON5 to plain JSON via your terminal., (*10)

Usage: json5 [OPTIONS] [FILE]

  -h, --help  Shows help and usage information

  (Reading data from STDIN is not currently supported on Windows)

Examples:

Converting a file named file.json5:, (*11)

json5 file.json5

Converting a file and saving its output:, (*12)

json5 file.json5 > file.json

Converting from STDIN:, (*13)

echo -e "{hello: 'world!'}" | json5

Converting from STDIN and saving the output:, (*14)

echo -e "{hello: 'world!'}" | json5 > output.json

Change log

Please see CHANGELOG for more information on what has changed recently., (*15)

Testing

bash composer test, (*16)

Contributing

Please see CONTRIBUTING and CODE_OF_CONDUCT for details., (*17)

Security

If you discover any security related issues, please email colinodell@gmail.com instead of using the issue tracker., (*18)

Support

In addition to standard support, consider a Tidelift Subscription for professional support and get alerted when new releases or security issues come out., (*19)

Credits

License

The MIT License (MIT). Please see License File for more information., (*20)

The Versions

15/01 2018

dev-master

9999999-dev https://github.com/colinodell/json5

UTF-8 compatible JSON5 parser for PHP

  Sources   Download

MIT

The Requires

  • ext-mbstring *
  • php ^5.4.8|^7.0
  • ext-json *

 

The Development Requires

json json_decode json5 json5_decode

15/01 2018

v1.0.4

1.0.4.0 https://github.com/colinodell/json5

UTF-8 compatible JSON5 parser for PHP

  Sources   Download

MIT

The Requires

  • php ^5.4.8|^7.0
  • ext-json *
  • ext-mbstring *

 

The Development Requires

json json_decode json5 json5_decode

15/01 2018

dev-byte-offset

dev-byte-offset https://github.com/colinodell/json5

UTF-8 compatible JSON5 parser for PHP

  Sources   Download

MIT

The Requires

  • php ^5.4.8|^7.0
  • ext-json *
  • ext-mbstring *

 

The Development Requires

json json_decode json5 json5_decode

14/01 2018

v1.0.3

1.0.3.0 https://github.com/colinodell/json5

UTF-8 compatible JSON5 parser for PHP

  Sources   Download

MIT

The Requires

  • php ^5.4.8|^7.0
  • ext-json *
  • ext-mbstring *

 

The Development Requires

json json_decode json5 json5_decode

14/01 2018

v1.0.2

1.0.2.0 https://github.com/colinodell/json5

UTF-8 compatible JSON5 parser for PHP

  Sources   Download

MIT

The Requires

  • php ^5.4.8|^7.0
  • ext-json *
  • ext-mbstring *

 

The Development Requires

json json_decode json5 json5_decode

11/11 2017

v1.0.1

1.0.1.0 https://github.com/colinodell/json5

UTF-8 compatible JSON5 parser for PHP

  Sources   Download

MIT

The Requires

  • php ^5.4.8|^7.0
  • ext-json *
  • ext-mbstring *

 

The Development Requires

json json_decode json5 json5_decode

11/11 2017

v1.0.0

1.0.0.0 https://github.com/colinodell/json5

JSON5 - JSON for Humans

  Sources   Download

MIT

The Requires

  • php ^5.4.8|^7.0
  • ext-json *
  • ext-mbstring *

 

The Development Requires

json json_decode json5 json5_decode