• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

colinodell/json5: UTF-8 compatible JSON5 parser for PHP

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

colinodell/json5

开源软件地址:

https://github.com/colinodell/json5

开源编程语言:

PHP 99.9%

开源软件介绍:

JSON5 for PHP - JSON for Humans

Latest Version on Packagist PHP 7.1+ Software License Build Status Coverage Status SensioLabs Insight UTF-8 Compatible Total Downloads

This library is a PHP fork of the JSON5 reference implementation.

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

{
    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: 'a trailing comma',
    oh: [
        "we shouldn't forget",
        'arrays can have',
        'trailing commas too',
    ],
}

See the JSON5 website for additional examples and details.

Install

Via Composer

$ composer require colinodell/json5

Usage

This package adds a json5_decode() function which is a drop-in replacement for PHP's built-in json_decode():

$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.

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.

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.

For users on PHP 7.2 and below: a PHP 7.3 polyfill is included with this library so that you can safely reference \JsonException and JSON_THROW_ON_ERROR in your own code.

Binary / Executable

A binary/executable named json5 is also provided for converting JSON5 to plain JSON via your terminal.

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:

json5 file.json5

Converting a file and saving its output:

json5 file.json5 > file.json

Converting from STDIN:

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

Converting from STDIN and saving the output:

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

Change log

Please see CHANGELOG for more information on what has changed recently.

Testing

$ composer test

Contributing

Please see CONTRIBUTING and CODE_OF_CONDUCT for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Support

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

Credits

License

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




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap