JSON5 The Human-Friendly JSON Format

JSON with comments, trailing commas, unquoted keys and single quotes. Every JSON file you already have is valid JSON5 - edit the sample below and watch it turn into strict JSON.

A strict machine rejecting a note while a warm workbench shows a commented JSON5 config with a trailing comma
100% backward compatible with JSON

Try It: Edit JSON5, Get JSON

Runs in your browser. Nothing is uploaded.

Strict JSON a machine gets

{
  "name": "my-app",
  "port": 8080,
  "ratio": 0.5,
  "features": [
    "comments",
    "trailing commas"
  ]
}

Valid JSON5. Edit the left side to see the JSON change.

Full validator

What is JSON5?

JSON5 is an extension of JSON that aims to make it easier for humans to write and maintain by hand. It adds minimal syntax features directly from ECMAScript 5.1.

Think of it as JSON for configuration files - where readability and ease of editing matter more than strict data interchange.

The picture on the right is the whole idea: JSON sits entirely inside JSON5. Nothing you can write in JSON is rejected, and everything JSON5 adds is syntax JavaScript already had.

2012

First release, on May 27. The parser has been in production for over a decade.

v1.0.0

The specification, published March 2018 and unchanged since.

0

Runtime dependencies in the reference parser.

100%

Of valid JSON documents are valid JSON5.

A JSON sphere sitting entirely inside a larger JSON5 sphere
A strict superset: all of JSON, plus a small ring of extras.

Full backward compatibility: All valid JSON files are valid JSON5 files. You can start using JSON5 features gradually.

Six Things JSON Will Not Let You Do

Everything you love about JSON, plus developer-friendly enhancements from ES5. Each card is real, parseable JSON5.

Six glass tiles showing comments, trailing commas, unquoted keys, single quotes, special numbers and multi-line strings
All six come from ECMAScript 5.1. JSON5 invents no syntax of its own, which is why any JavaScript developer can read it on sight. How JSON5 relates to ECMAScript

Comment iconComments

Say why a setting has the value it has.

// raised after an outage timeout: 30, /* seconds */

List iconTrailing Commas

Add a line without touching the one above it.

[ 'lint', 'test', ]

Key iconUnquoted Keys

Skip the quotes on any valid identifier.

{ name: "api", $schema: "v2" }

Quote iconSingle Quotes

Stop escaping every double quote.

greeting: 'She said "hi"'

Infinity iconMore Numbers

Hex, bare decimals, a plus sign, Infinity, NaN.

[0xFF, .5, 5., +1, Infinity, NaN]

Text format iconMulti-line Strings

Wrap a long string with a backslash.

help: 'Wraps here \ and continues'

JSON5 Comments: The Rules

Comments are the reason most people switch. Plain JSON has none - JSON.parse throws a SyntaxError at the first slash. JSON5 takes both JavaScript forms, with JavaScript's rules.

{ // A line comment runs to the end of the line. port: 8080, // after a value is fine too /* A block comment can span several lines. */ hosts: ['a.example', /* inline */ 'b.example'], // Inside a string, slashes are just text: docs: 'https://example.com/docs', }

Next step iconAnywhere white space goes

Before a key, after a value, between array items, at the top or bottom of the file. Never inside a string or a number.

Layers iconBlock comments do not nest

The first */ closes the comment, exactly as in JavaScript. Commenting out a block that already holds one breaks the file.

Edit iconParsing drops them

The parsed object has no trace of a comment, so JSON5.stringify cannot write them back. A tool that edits a file in place needs a round-trip parser.

Hashtag iconNo # comments

That is YAML and TOML. In JSON5 a # outside a string is a syntax error.

What to write in them, and what not to: comment best practices. Keeping comments through an edit in Python: json-five.

Is It Valid JSON5?

Six one-liners. Call each one, and the reference parser settles it on the spot. Two of them catch almost everybody.

0 of 6 correct

  1. { name: 'api', }

  2. { env: production }

  3. { class: 1, if: 2 }

  4. { mode: 0755 }

  5. [0xFF, .5, +1, Infinity]

  6. [1, , 3]

Want all ten traps? They are on the cheat sheet.

One Config File, Annotated

Eleven lines that use most of what JSON5 adds. Strip the comments and the trailing commas and you are back to plain JSON.

// Configuration file in JSON5 { name: 'my-app', version: 2.0, port: 0x1F90, // 8080 in hex features: [ 'comments', 'trailing commas', 'unquoted keys', // trailing comma OK! ], /* Multi-line comments are also supported */ enabled: true, threshold: .5, // leading decimal }
A code editor on a desk showing a JSON5 config with hand-drawn arrows
More files like this, ready to copy: JSON5 examples.

This file is both valid JSON5 and valid ES5 JavaScript!

JSON vs JSON5

See what JSON5 adds to make your config files more readable.

Feature JSON JSON5
Comments No Not allowed Yes // and /* */
Trailing commas No Syntax error Yes Allowed
Unquoted keys No Must quote all Yes If valid identifier
String quotes No Double only Yes Single or double
Hex numbers No Not supported Yes 0xDECAF
Infinity/NaN No Not supported Yes Supported
Multi-line strings No Not supported Yes With \ escape
A strict JSON file with red errors beside the same data as a friendly JSON5 file with green checks
JSON is still the right answer for APIs. The full comparison, with measured parse speed.

Switching Is One Parser Call

There is no migration to plan. Your files are already valid, so adoption is one changed line and then as much or as little new syntax as you want.

Workflow diagram titled From JSON to JSON5 in Five Steps: Keep Your JSON, Swap the Parser, Add Comments, Set Up Your Editor, Validate in CI
  1. 1 Keep your JSONRename to .json5 or do not. Nothing in the file has to change on day one.
  2. 2 Swap the parserReplace JSON.parse with JSON5.parse, or the equivalent in your language.
  3. 3 Add commentsWrite down why each setting exists while you still remember.
  4. 4 Set up your editorHighlighting and formatting, so a stray comma shows up as you type.
  5. 5 Validate in CIParse every config in the pipeline, so a bad file fails the build and not the deploy.

Where JSON5 Already Runs

You have probably parsed JSON5 without installing anything. Each claim links to the project's own documentation - check them.

Hub diagram titled Where JSON5 Already Runs: JSON5 at the center, joined to SQLite, Apple Platforms (allowsJSON5), Chromium (.json5 build data), Babel and Renovate (renovate.json5)
A database, an operating system's decoder, a browser's source tree, a compiler and a bot. None of them asks you to install a JSON5 library.

SQLite logoSQLite

Since version 3.42.0 (May 2023), the built-in JSON functions accept JSON5 input.

SQLite JSON documentation

iOS logoApple Platforms

Foundation's JSONDecoder has an allowsJSON5 switch on iOS 15 and macOS 12 and later.

Apple developer documentation

Chrome logoChromium

The browser's source tree keeps build data such as its runtime feature flags in .json5 files.

runtime_enabled_features.json5

Babel logoBabel

Babel reads its JSON config files with a JSON5 parser, so comments in them just work.

Babel config guide

Renovate logoRenovate

The dependency-update bot accepts a renovate.json5 config file out of the box.

Renovate configuration docs

Pick Your Language

Install command, working examples and library choice for each one.

Hub diagram titled One Format, Eight Languages: JSON5 at the center, joined to JavaScript (JSON5.parse), TypeScript (types included), Node.js (npm install json5), Python (pip install json5), Go (titanous/json5), Rust (cargo add json5), Java (at.syntaxerror:json5) and C# (dotnet add package Json5)
The same file parses everywhere. Every command is on the cheat sheet.

Four Questions Before You Switch

Is JSON5 the same as JSON with comments?

No. JSONC, the format VS Code uses for its settings, adds comments and tolerates trailing commas. JSON5 adds those plus unquoted keys, single quotes, multi-line strings and extra number forms. See all five formats side by side.

Can JSON.parse read a JSON5 file?

Only if the file happens to use no JSON5 features. The moment it contains a comment or a trailing comma you need a JSON5 parser. Going the other way always works: a JSON5 parser reads any JSON.

Should my API return JSON5?

No. Use JSON between programs: every language parses it natively and far faster. JSON5 is for files people write. A common pattern is to author in JSON5 and ship JSON.

What happens to my comments when a program rewrites the file?

They are lost. Parsers discard comments, so parse-then-stringify produces a file without them. Treat JSON5 configs as hand-edited source, not as something tools write back to.

All frequently asked questions

A glowing path toward a curly-brace doorway past signposts for guides, examples and a cheat sheet

Ready to Learn More?

Explore our comprehensive guides, examples, and resources to master JSON5.