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.
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 validatorWhat Brought You Here?
Most people arrive with one of three jobs: deciding whether to use JSON5, writing it, or getting it to run.
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 comparisonDeciding
Writing
Getting it to run
Not Python? Each of these has its own guide:
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.
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.
Comments
Say why a setting has the value it has.
// raised after an outage
timeout: 30, /* seconds */
Trailing Commas
Add a line without touching the one above it.
[
'lint',
'test',
]
Unquoted Keys
Skip the quotes on any valid identifier.
{ name: "api",
$schema: "v2" }
Single Quotes
Stop escaping every double quote.
greeting:
'She said "hi"'
More Numbers
Hex, bare decimals, a plus sign, Infinity, NaN.
[0xFF, .5, 5., +1,
Infinity, NaN]
Multi-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',
}
Anywhere 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.
Block comments do not nest
The first */ closes the comment, exactly as in JavaScript. Commenting out a block that already holds one breaks the file.
Parsing 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.
No # 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
-
{ name: 'api', } -
{ env: production } -
{ class: 1, if: 2 } -
{ mode: 0755 } -
[0xFF, .5, +1, Infinity] -
[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
}
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 | ||
| Trailing commas | ||
| Unquoted keys | ||
| String quotes | ||
| Hex numbers | ||
| Infinity/NaN | ||
| Multi-line strings |
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.
- 1 Keep your JSONRename to
.json5or do not. Nothing in the file has to change on day one. - 2 Swap the parserReplace
JSON.parsewithJSON5.parse, or the equivalent in your language. - 3 Add commentsWrite down why each setting exists while you still remember.
- 4 Set up your editorHighlighting and formatting, so a stray comma shows up as you type.
- 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.
SQLite
Since version 3.42.0 (May 2023), the built-in JSON functions accept JSON5 input.
SQLite JSON documentation
Apple Platforms
Foundation's JSONDecoder has an allowsJSON5 switch on iOS 15 and macOS 12 and later.
Chromium
The browser's source tree keeps build data such as its runtime feature flags in .json5 files.
Babel
Babel reads its JSON config files with a JSON5 parser, so comments in them just work.
Babel config guide
Renovate
The dependency-update bot accepts a renovate.json5 config file out of the box.
Perfect For
JSON5 shines wherever humans edit JSON by hand.
Config Files
App settings with the reasoning written beside them. Guides for 18 tools, from Vite to Kubernetes.
Package Manifests
Dependencies annotated with why each one is pinned where it is.
Data Files
Hand-maintained datasets a person can scan and edit without a linter open.
Test Fixtures
Mock data that says what each record is there to prove.
Pick Your Language
Install command, working examples and library choice for each one.
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.
Ready to Learn More?
Explore our comprehensive guides, examples, and resources to master JSON5.
JavaScript
Python
TypeScript
Node.js
Rust
Java
C#
Ruby
Kotlin
Vite
webpack
ESLint
Prettier
VS Code
JetBrains