PHPackages                             colinodell/json5 - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. colinodell/json5

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

colinodell/json5
================

UTF-8 compatible JSON5 parser for PHP

v3.0.0(2y ago)30422.2M—4.1%1320MITPHPPHP ^8.0CI passing

Since Nov 11Pushed 5mo ago8 watchersCompare

[ Source](https://github.com/colinodell/json5)[ Packagist](https://packagist.org/packages/colinodell/json5)[ Docs](https://github.com/colinodell/json5)[ Fund](https://www.colinodell.com/sponsor)[ Fund](https://www.paypal.me/colinpodell/10.00)[ RSS](/packages/colinodell-json5/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (6)Versions (14)Used By (20)

JSON5 for PHP - JSON for Humans
===============================

[](#json5-for-php---json-for-humans)

[![Latest Version on Packagist](https://camo.githubusercontent.com/65914a276f06717066e8ecf6c826f332fe2f6b93c9b84c8caa08abe0beb911e8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f636f6c696e6f64656c6c2f6a736f6e352e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/colinodell/json5)[![PHP 8.0+](https://camo.githubusercontent.com/0d498eb024ab26f822b325fccb13db4898cd66568890fd54922e3103132feb4c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f636f6c696e6f64656c6c2f6a736f6e352e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/colinodell/json5)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/a64859963d28099b5d2151b5b1e01a7582825a672c7161905fde57e3669340c2/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f636f6c696e6f64656c6c2f6a736f6e352f74657374732e796d6c3f6272616e63683d6d61696e267374796c653d666c61742d737175617265)](https://github.com/colinodell/json5/actions?query=workflow%3ATests+branch%3Amain)[![Coverage Status](https://camo.githubusercontent.com/5ff98e3f5cbe47025f179351d32203d0651083f752a4960a5648e69f74117f98/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f636f6c696e6f64656c6c2f6a736f6e352e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/colinodell/json5/code-structure/main/code-coverage)[![SensioLabs Insight](https://camo.githubusercontent.com/51732ac614159a65910a165db89934b682e39268fd55dffb341d2e51fb38adb4/68747470733a2f2f696d672e736869656c64732e696f2f73796d666f6e792f692f67726164652f39323061626233622d613764302d343331612d626235612d3938333164313432363930653f7374796c653d666c61742d737175617265)](https://insight.symfony.com/projects/920abb3b-a7d0-431a-bb5a-9831d142690e)[![UTF-8 Compatible](https://camo.githubusercontent.com/a3b32c17760a51d982e9c561abb606b8da5e286882c2b35ab63d7ea679ea8ff6/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7574662d2d382d636f6d70617469626c652d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/a3b32c17760a51d982e9c561abb606b8da5e286882c2b35ab63d7ea679ea8ff6/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7574662d2d382d636f6d70617469626c652d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)[![Total Downloads](https://camo.githubusercontent.com/cc8a3ff46eca057d0d5402637ff393e94e1b1520ba96bc9670b9f5286b2ec9ef/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f636f6c696e6f64656c6c2f6a736f6e352e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/colinodell/json5)

This library is a PHP fork of the [JSON5 reference implementation](https://github.com/json5/json5).

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](http://json5.org).

Install
-------

[](#install)

Via Composer

```
composer require colinodell/json5
```

Usage
-----

[](#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](http://php.net/manual/en/function.json-decode.php).

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

[](#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.

Binary / Executable
-------------------

[](#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:

[](#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
----------

[](#change-log)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Testing
-------

[](#testing)

```
composer test
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) and [CODE\_OF\_CONDUCT](CODE_OF_CONDUCT.md) for details.

Security
--------

[](#security)

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

Support
-------

[](#support)

In addition to standard support, [consider a Tidelift Subscription for professional support and get alerted when new releases or security issues come out](https://tidelift.com/subscription/pkg/packagist-colinodell-json5?utm_source=packagist-colinodell-json5&utm_medium=referral&utm_campaign=readme).

Credits
-------

[](#credits)

- [Colin O'Dell](https://github.com/colinodell)
- [Aseem Kishore](https://github.com/aseemk), [the JSON5 project](https://github.com/json5/json5), and [their contributors](https://github.com/json5/json5#credits)
- [All other contributors to this project](https://github.com/colinodell/json5/graphs/contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

60

—

FairBetter than 99% of packages

Maintenance49

Moderate activity, may be stable

Popularity66

Solid adoption and visibility

Community35

Small or concentrated contributor base

Maturity75

Established project with proven stability

 Bus Factor1

Top contributor holds 91.2% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~190 days

Recently: every ~291 days

Total

13

Last Release

829d ago

Major Versions

v1.0.5 → v2.0.02018-09-20

v2.3.0 → v3.0.02024-02-09

PHP version history (4 changes)v1.0.0PHP ^5.4.8|^7.0

v2.1.0PHP ^5.6|^7.0

v2.2.0PHP ^7.1.3|^8.0

v3.0.0PHP ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/4325b62a6ad366c731c3120595d861469be50f9da88df3ea99752c30ff98c179?d=identicon)[colinodell](/maintainers/colinodell)

---

Top Contributors

[![colinodell](https://avatars.githubusercontent.com/u/202034?v=4)](https://github.com/colinodell "colinodell (155 commits)")[![tacman](https://avatars.githubusercontent.com/u/619585?v=4)](https://github.com/tacman "tacman (4 commits)")[![glensc](https://avatars.githubusercontent.com/u/199095?v=4)](https://github.com/glensc "glensc (3 commits)")[![Chris53897](https://avatars.githubusercontent.com/u/7104259?v=4)](https://github.com/Chris53897 "Chris53897 (2 commits)")[![inhere](https://avatars.githubusercontent.com/u/5302062?v=4)](https://github.com/inhere "inhere (2 commits)")[![KarelWintersky](https://avatars.githubusercontent.com/u/2164874?v=4)](https://github.com/KarelWintersky "KarelWintersky (2 commits)")[![Yurunsoft](https://avatars.githubusercontent.com/u/20104656?v=4)](https://github.com/Yurunsoft "Yurunsoft (1 commits)")[![ahmedash95](https://avatars.githubusercontent.com/u/8272048?v=4)](https://github.com/ahmedash95 "ahmedash95 (1 commits)")

---

Tags

hacktoberfestjsonjson5phpjsonjson\_decodeJSON5json5\_decode

###  Code Quality

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/colinodell-json5/health.svg)

```
[![Health](https://phpackages.com/badges/colinodell-json5/health.svg)](https://phpackages.com/packages/colinodell-json5)
```

###  Alternatives

[justinrainbow/json-schema

A library to validate a json schema.

3.6k316.9M612](/packages/justinrainbow-json-schema)[mtdowling/jmespath.php

Declaratively specify how to extract elements from a JSON document

2.0k472.8M135](/packages/mtdowling-jmespathphp)[jms/serializer

Library for (de-)serializing data of any complexity; supports XML, and JSON.

2.3k135.8M851](/packages/jms-serializer)[jms/serializer-bundle

Allows you to easily serialize, and deserialize data of any complexity

1.8k89.3M627](/packages/jms-serializer-bundle)[clue/ndjson-react

Streaming newline-delimited JSON (NDJSON) parser and encoder for ReactPHP.

15467.7M16](/packages/clue-ndjson-react)[ergebnis/json-printer

Provides a JSON printer, allowing for flexible indentation.

9138.2M24](/packages/ergebnis-json-printer)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
