# JSON5 - Human-Friendly JSON with Comments & Trailing Commas


Source: https://json5.dev/

---

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

[Learn JSON5](https://json5.dev/learn/) [JSON vs JSON5](https://json5.dev/compare/) [Cheat Sheet](https://json5.dev/cheatsheet/)

![A strict machine rejecting a note while a warm workbench shows a commented JSON5 config with a trailing comma](https://json5.dev/img/hero/home.png)

100% backward compatible with JSON

## JSON5 Playground: Edit JSON5, Get JSON

Runs in your browser. Nothing is uploaded.

JSON5 you write 

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](https://json5.dev/tools/online-validator/)

## What Brought You Here?

Most people arrive with one of three jobs: deciding whether to use JSON5, writing it, or getting it to run.

[![Two glass monoliths labeled JSON and JSON5 side by side](https://json5.dev/img/thumb/compare.png)

Deciding

### JSON vs JSON5

Every syntax difference in one table, parse speed we measured ourselves, how it stacks up against JSONC, YAML and TOML, and a one-question rule for choosing.

Read the comparison

](https://json5.dev/compare/)

Deciding

 [![Illustration for the JSON5 frequently asked questions](https://json5.dev/img/thumb/faq.png) FAQShort answers before you commit.](https://json5.dev/faq/)[![A blueprint of a curly-brace building stamped v1.0.0](https://json5.dev/img/thumb/spec.png) The SpecificationWhat it says, and what it leaves out.](https://json5.dev/spec/)

Writing

 [![A one-page JSON5 reference sheet pinned to a corkboard](https://json5.dev/img/thumb/cheatsheet.png) Cheat SheetAll of the syntax on one printable page.](https://json5.dev/cheatsheet/)[![Illustration of a code editor highlighting a JSON5 file](https://json5.dev/img/thumb/tools-vscode.png) VS Code SetupHighlighting and formatting for .json5.](https://json5.dev/tools/vscode/)

Getting it to run

 [![JSON5 documents turning into Python dictionaries](https://json5.dev/img/thumb/python.png) JSON5 for PythonWhich library, and how slow is slow.](https://json5.dev/python/)[![Illustration of JSON5 editors, validators and converters](https://json5.dev/img/thumb/tools.png) Online ToolsValidate, convert, format, minify. ](https://json5.dev/tools/)[![Illustration for fixing JSON5 parse errors](https://json5.dev/img/thumb/troubleshooting.png) TroubleshootingParse errors and what causes them.](https://json5.dev/troubleshooting/)

Not Python? Each of these has its own guide:

[JavaScript](https://json5.dev/javascript/) [TypeScript](https://json5.dev/typescript/) [Go](https://json5.dev/go/) [Rust](https://json5.dev/rust/) [Java](https://json5.dev/java/) [C#](https://json5.dev/csharp/)

## 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](https://json5.dev/img/home/what-is.png)

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](https://json5.dev/img/home/features.png)

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](https://json5.dev/spec/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](https://json5.dev/tutorials/comments-best-practices/). Keeping comments through an edit in Python: [json-five](https://json5.dev/python/#alternatives).

## 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](https://json5.dev/cheatsheet/#not-allowed).

## 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](https://json5.dev/img/home/example.png)

More files like this, ready to copy: [JSON5 examples](https://json5.dev/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](https://json5.dev/images/icons/no.png) Not allowed

![Yes](https://json5.dev/images/icons/yes.png) // and /\* \*/

Trailing commas

![No](https://json5.dev/images/icons/no.png) Syntax error

![Yes](https://json5.dev/images/icons/yes.png) Allowed

Unquoted keys

![No](https://json5.dev/images/icons/no.png) Must quote all

![Yes](https://json5.dev/images/icons/yes.png) If valid identifier

String quotes

![No](https://json5.dev/images/icons/no.png) Double only

![Yes](https://json5.dev/images/icons/yes.png) Single or double

Hex numbers

![No](https://json5.dev/images/icons/no.png) Not supported

![Yes](https://json5.dev/images/icons/yes.png) 0xDECAF

Infinity/NaN

![No](https://json5.dev/images/icons/no.png) Not supported

![Yes](https://json5.dev/images/icons/yes.png) Supported

Multi-line strings

![No](https://json5.dev/images/icons/no.png) Not supported

![Yes](https://json5.dev/images/icons/yes.png) With \\ escape

![A strict JSON file with red errors beside the same data as a friendly JSON5 file with green checks](https://json5.dev/img/home/compare.png)

JSON is still the right answer for APIs. [The full comparison, with measured parse speed](https://json5.dev/compare/).

## 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](https://json5.dev/img/home/workflow.png)

1.  1 [Keep your JSON](https://json5.dev/tutorials/migration-from-json/)Rename to `.json5` or do not. Nothing in the file has to change on day one.
2.  2 [Swap the parser](https://json5.dev/javascript/)Replace `JSON.parse` with `JSON5.parse`, or the equivalent in your language.
3.  3 [Add comments](https://json5.dev/tutorials/comments-best-practices/)Write down why each setting exists while you still remember.
4.  4 [Set up your editor](https://json5.dev/tools/vscode/)Highlighting and formatting, so a stray comma shows up as you type.
5.  5 [Validate in CI](https://json5.dev/tools/validation/)Parse 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)](https://json5.dev/img/sections/home-ecosystem.png)

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](https://www.sqlite.org/json1.html#json5)

### iOS logoApple Platforms

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

[Apple developer documentation](https://developer.apple.com/documentation/foundation/jsondecoder/allowsjson5)

### Chrome logoChromium

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

[runtime\_enabled\_features.json5](https://chromium.googlesource.com/chromium/src/+/main/third_party/blink/renderer/platform/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](https://json5.dev/config/babel/)

### Renovate logoRenovate

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

[Renovate configuration docs](https://docs.renovatebot.com/configuration-options/)

## Perfect For

JSON5 shines wherever humans edit JSON by hand.

![Four islands for config files, package manifests, data files and test fixtures](https://json5.dev/img/home/use-cases.png)

[

### Settings iconConfig Files

App settings with the reasoning written beside them. Guides for 18 tools, from Vite to Kubernetes.

](https://json5.dev/config/)[

### Layers iconPackage Manifests

Dependencies annotated with why each one is pinned where it is.

](https://json5.dev/examples/)[

### Database iconData Files

Hand-maintained datasets a person can scan and edit without a linter open.

](https://json5.dev/tutorials/first-config-file/)[

### Test iconTest Fixtures

Mock data that says what each record is there to prove.

](https://json5.dev/tutorials/schema-validation/)

## Pick Your Language

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

[![JavaScript logo](https://json5.dev/images/tech/javascript.png)JavaScript](https://json5.dev/javascript/) [![TypeScript logo](https://json5.dev/images/tech/typescript.png)TypeScript](https://json5.dev/typescript/) [![Node.js logo](https://json5.dev/images/tech/nodejs.png)Node.js](https://json5.dev/nodejs/) [![Python logo](https://json5.dev/images/tech/python.png)Python](https://json5.dev/python/) [![Go logo](https://json5.dev/images/tech/go.png)Go](https://json5.dev/go/) [![Rust logo](https://json5.dev/images/tech/rust.png)Rust](https://json5.dev/rust/) [![Java logo](https://json5.dev/images/tech/java.png)Java](https://json5.dev/java/) [![C# logo](https://json5.dev/images/tech/csharp.png)C#](https://json5.dev/csharp/)

![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)](https://json5.dev/img/sections/home-languages.png)

The same file parses everywhere. Every command is on the [cheat sheet](https://json5.dev/cheatsheet/#install).

## 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](https://json5.dev/compare/#formats).

### 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](https://json5.dev/faq/)

![A glowing path toward a curly-brace doorway past signposts for guides, examples and a cheat sheet](https://json5.dev/img/home/cta.png)

## Ready to Learn More?

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

[Why JSON5?](https://json5.dev/why/) [Download Cheat Sheet](https://json5.dev/cheatsheet/)
