• Stars
    star
    275
  • Rank 149,796 (Top 3 %)
  • Language
    PHP
  • License
    MIT License
  • Created about 7 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

UTF-8 compatible JSON5 parser for PHP

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: [
        'some trailing commas',
    ],
}

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.

More Repositories

1

mqtt-control-panel

A simple alarm control panel for Home Assistant's manual_mqtt alarm. Designed to run on a Raspberry Pi using an Adafruit 3.5" PiTFT.
Python
86
star
2

python-qnapstats

Python API for obtaining QNAP NAS system stats
Python
72
star
3

indentation

PHP library to detect and manipulate indentation of strings and files
PHP
39
star
4

git-amend-old

DEPRECATED Bash script to amend older commits with staged changes - see:
Shell
23
star
5

php-iot-examples

Demos for "Rise of the Machines: PHP and IoT"
PHP
20
star
6

google-meet-hass-extension

Chrome extension that updates a Home Assistant entity state with the status of your Google Meet calls
TypeScript
14
star
7

psr-testlogger

PSR-3 compliant test logger based on psr/log v1's
PHP
14
star
8

var-packagist-search

Quickly thrown together code to scan popular Packagist libs for PHP's "var" keyword
PHP
10
star
9

go-check-ssl

Simple command line utility to check the status of an SSL certificate
Go
8
star
10

cookiecache

Distributed PSR-16 cache implementation for PHP 6 that uses browser cookies to store data
PHP
8
star
11

omnipay-bundle

Omnipay bundle for Symfony 2.3+ and 3.0+
PHP
7
star
12

tunegenie-spotify

Generate Spotify playlists from TuneGenie data
CoffeeScript
6
star
13

phpcs-magento

phpcs sniffs for Magento
4
star
14

franz-twitch

Twitch recipe for Franz 5
JavaScript
3
star
15

cryptopals

PHP
3
star
16

static-response-server

Super tiny HTTP server that always returns the same response
Go
3
star
17

omnipay-zero

Zero-amount payment driver for Omnipay
PHP
2
star
18

lync-productivity-timer

Automatically sets your Lync status to "Busy" or "DND" for x minutes
C#
2
star
19

slack-status

PyGTK application for easy Slack status switching via your notification area
Python
2
star
20

phpstorm-colors

My custom color scheme for PhpStorm
2
star
21

advent-2020

My solutions to https://adventofcode.com/2020 using Golang
Go
2
star
22

docker-php-beta

PHP Beta Docker Images
Shell
1
star
23

mcforge

Copy of the MCForge project I used to lead. NO LONGER MAINTAINED.
C#
1
star
24

advent-2022

Advent of Code 2022 solutions in Kotlin
Kotlin
1
star
25

afpl

April Fools' Public License - a permissive free software license
1
star
26

Samsung-Market-Download-Test

Source for com.samsung.downloadtestapp
Java
1
star
27

dotcom-legacy

Source code for my old single-page website
1
star
28

docker-php-7.2-prerelease

Pre-release builds of PHP 7.2 for Docker
Shell
1
star
29

bigbrother

bukkit plugin to record certain player events
Java
1
star
30

ansible-role-prtg-mini-probe

Installs the PRTG Mini Probe onto Debian-based systems.
Shell
1
star
31

aoc-downloader

PHP-based utility to download all Advent of Code puzzles and inputs
PHP
1
star
32

mutesync-streamdeck-plugin

Unofficial integration to control the mutesync virtual button with the Elgato Stream Deck
JavaScript
1
star
33

AdafruitSerialRGBLCD

Firmware library for Adafruit's USB + Serial Backpack Kit with 16x2 RGB LCD
C++
1
star