PHPackages                             serafim/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. serafim/json5

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

serafim/json5
=============

JSON5 parser

1.0.0(4y ago)231.1kMITPHPPHP ^8.1CI failing

Since Dec 15Pushed 4y ago1 watchersCompare

[ Source](https://github.com/SerafimArts/Json5)[ Packagist](https://packagist.org/packages/serafim/json5)[ Docs](https://github.com/SerafimArts/Json5)[ RSS](/packages/serafim-json5/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (4)Dependencies (10)Versions (5)Used By (0)

JSON 5
======

[](#json-5)

 [![](https://github.com/SerafimArts/Json5/workflows/build/badge.svg)](https://github.com/SerafimArts/Json5/actions)

 [![Latest Stable Version](https://camo.githubusercontent.com/882ed84bd2dd696a9bf42b8ebf3e514d0e3de7f32d7976418feb01cd95d58405/68747470733a2f2f706f7365722e707567782e6f72672f7365726166696d2f6a736f6e352f726571756972652f7068703f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/serafim/json5) [![Latest Stable Version](https://camo.githubusercontent.com/90e8ed7e3801ef139a563debe9db3cdbeedb7496b1d6bf670530a2162515b17c/68747470733a2f2f706f7365722e707567782e6f72672f7365726166696d2f6a736f6e352f76657273696f6e3f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/serafim/json5) [![Latest Unstable Version](https://camo.githubusercontent.com/3cd2d503d2f6f8a80f72cae600b18aa0b6d07ce2a9fd1361b712d8dd0e679484/68747470733a2f2f706f7365722e707567782e6f72672f7365726166696d2f6a736f6e352f762f756e737461626c653f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/serafim/json5) [![Total Downloads](https://camo.githubusercontent.com/ee4daca735980a0ce41feb2dbc43faeaed543d248ff33efc98ba676289268bc4/68747470733a2f2f706f7365722e707567782e6f72672f7365726166696d2f6a736f6e352f646f776e6c6f6164733f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/serafim/json5) [![License MIT](https://camo.githubusercontent.com/cfd4a762d0833a03ffba7c568590df961d50e077654812f1c1dbc666ff9c2e5b/68747470733a2f2f706f7365722e707567782e6f72672f7365726166696d2f6a736f6e352f6c6963656e73653f7374796c653d666f722d7468652d6261646765)](https://raw.githubusercontent.com/SerafimArts/Json5/master/LICENSE.md)

The JSON5 Data Interchange Format (JSON5) is a superset of [JSON](https://tools.ietf.org/html/rfc7159) that aims to alleviate some of the limitations of JSON by expanding its syntax to include some productions from [ECMAScript 5.1](https://www.ecma-international.org/ecma-262/5.1/).

This PHP library for JSON5 parsing and serialization based on [pp2 grammar](https://github.com/SerafimArts/json5/blob/master/resources/grammar.pp2)and contains [full AST](https://github.com/SerafimArts/json5/tree/master/src/Ast) building process.

Summary of Features
-------------------

[](#summary-of-features)

The following ECMAScript 5.1 features, which are not supported in JSON, have been extended to JSON5.

### Objects

[](#objects)

- Object keys may be an ECMAScript 5.1 *[IdentifierName](https://www.ecma-international.org/ecma-262/5.1/#sec-7.6)*.
- Objects may have a single trailing comma.

### Arrays

[](#arrays)

- Arrays may have a single trailing comma.

### Strings

[](#strings)

- Strings may be single quoted.
- Strings may span multiple lines by escaping new line characters.
- Strings may include character escapes.

### Numbers

[](#numbers)

- Numbers may be hexadecimal.
- Numbers may have a leading or trailing decimal point.
- Numbers may be [IEEE 754](http://ieeexplore.ieee.org/servlet/opac?punumber=4610933) positive infinity, negative infinity, and NaN.
- Numbers may begin with an explicit plus sign.

### Comments

[](#comments)

- Single and multi-line comments are allowed.

### White Space

[](#white-space)

- Additional white space characters are allowed.

Short Example
-------------

[](#short-example)

```
{
    // comments
    unquoted: 'and you can quote me on that',
    singleQuotes: 'I can use "double quotes" here',
    lineBreaks: "Look, Mom! \
No \\n's!",
    hexadecimal: 0xdecaf,
    leadingDecimalPoint: .8675309, andTrailing: 8675309.,
    positiveSign: +1,
    trailingComma: 'in objects', andIn: ['arrays',],
    "backwardsCompatible": "with JSON",
}
```

Specification
-------------

[](#specification)

For a detailed explanation of the JSON5 format, please read the [official specification](https://json5.github.io/json5-spec/).

Installation
------------

[](#installation)

Install via [Composer](https://getcomposer.org/):

```
composer require serafim/json5
```

Usage
-----

[](#usage)

```
$result = json5_decode( {#107
// >   +"unquoted": "and you can quote me on that"
// >   +"singleQuotes": "I can use "double quotes" here"
// >   +"lineBreaks": "Look, \' or '\ Mom! No \n's!"
// >   +"hexadecimal": -912559
// >   +"leadingDecimalPoint": -0.0003847
// >   +"andTrailing": 8675309.0
// >   +"positiveSign": -INF
// >   +"trailingComma": {#118
// >     +"obj": "in objects"
// >   }
// >   +"andIn": array:1 [
// >     0 => "arrays"
// >   ]
// >   +"backwardsCompatible": "with JSON"
// > }
//
```

Benchmarks
----------

[](#benchmarks)

- 100\_000 iterations (PHP 8.1 + JIT on Ryzen 9 5900X).

SampleTimeOperations (Per Second)`json_decode('42')`0.0112s8 917 408`json_decode('{"example": 42}')`0.0326s3 061 848`json5_decode('42')`0.0545s1 832 646`json5_decode('{example: 42}')`5.3956s18 533Yep... Native `json_decode` is faster =))

Issues
------

[](#issues)

To report bugs or request features regarding the JSON5 data format, please submit an issue to the [official specification repository](https://github.com/json5/json5-spec).

To report bugs or request features regarding the PHP implementation of JSON5, please submit an issue to this repository.

License
-------

[](#license)

See [LICENSE](https://github.com/SerafimArts/Json5/master/LICENSE.md)

###  Health Score

34

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity27

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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 ~157 days

Total

4

Last Release

1554d ago

Major Versions

0.1.0 → 1.0.0-alpha.12022-04-01

PHP version history (3 changes)0.1.0PHP ^7.4|^8.0

1.0.0-alpha.1PHP ^8.0

1.0.0PHP ^8.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/150420?v=4)[Ruslan Sharipov](/maintainers/Serafim)[@serafim](https://github.com/serafim)

---

Top Contributors

[![SerafimArts](https://avatars.githubusercontent.com/u/2461257?v=4)](https://github.com/SerafimArts "SerafimArts (25 commits)")

---

Tags

decoderencoderjson5parserjsonJSON5encodedecodereadwriteparsing

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[symfony/yaml

Loads and dumps YAML files

3.9k831.1M11.3k](/packages/symfony-yaml)[symfony/serializer

Handles serializing and deserializing data structures, including object graphs, into array structures or other formats like XML and JSON.

2.5k327.6M3.4k](/packages/symfony-serializer)[colinodell/json5

UTF-8 compatible JSON5 parser for PHP

30525.1M57](/packages/colinodell-json5)[yethee/tiktoken

PHP version of tiktoken

1624.0M30](/packages/yethee-tiktoken)[kherge/json

Encodes, decodes, and validates JSON data.

61237.7k6](/packages/kherge-json)[gioni06/gpt3-tokenizer

PHP package for Byte Pair Encoding (BPE) used by GPT-3.

84591.1k11](/packages/gioni06-gpt3-tokenizer)

PHPackages © 2026

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