JSON5 Explained: Features, Syntax & When to Use It
Published: October 7, 2026 ยท 8 min read ยท By JSON Suite Team
If you've ever wished you could add comments to your JSON config files, or been frustrated by a trailing comma error, JSON5 is the answer. It's a superset of JSON designed to be easier for humans to write and maintain.
What is JSON5?
JSON5 is an extension of JSON that adds features from ECMAScript 5.1 (ES5) to make it more human-friendly. It was created by Aseem Kishore in 2012 and is now a community-maintained standard.
The key philosophy: JSON5 is a strict subset of ES5, meaning any valid JSON5 is also valid JavaScript. This makes it intuitive for JavaScript developers and easy to eval() in a pinch (though you should use a proper parser).
JSON5 Features
1. Comments
Both single-line and multi-line comments are supported:
2. Trailing Commas
Add commas after the last item without errors:
3. Unquoted Object Keys
Keys can be unquoted if they're valid identifiers:
4. Single-Quoted Strings
Use single or double quotes interchangeably:
5. Hexadecimal Numbers
Hex notation for numbers (great for colors):
6. Special Numeric Values
Infinity and NaN are valid:
7. Leading/Trailing Decimal Points
Numbers can start or end with a decimal:
8. Multi-line Strings
Strings can span multiple lines using backslash escapes:
JSON vs JSONC vs JSON5
These three formats are often confused. Here's how they compare:
| Feature | JSON | JSONC | JSON5 |
|---|---|---|---|
| Comments | โ | โ | โ |
| Trailing commas | โ | โ | โ |
| Unquoted keys | โ | โ | โ |
| Single quotes | โ | โ | โ |
| Hex numbers | โ | โ | โ |
| Infinity/NaN | โ | โ | โ |
| Multi-line strings | โ | โ | โ |
| Leading/trailing decimals | โ | โ | โ |
| Standard | RFC 8259 | VS Code | json5.org |
JSONC (JSON with Comments) is a minimal extension used by VS Code for settings files. It only adds comments and trailing commas. JSON5 goes much further with a richer feature set.
When to Use JSON5
Good use cases:
- Configuration files โ Comments document settings, trailing commas simplify diffs
- Development fixtures โ Test data that humans edit frequently
- Build tool configs โ Babel, some webpack plugins support JSON5
- Local data files โ When only your code reads the file
Not recommended:
- API responses โ Clients expect standard JSON
- Data interchange โ Most parsers only support JSON
- Public files โ Broad compatibility requires standard JSON
Tools That Support JSON5
- Babel โ babel.config.json5
- Next.js โ next.config.json5 (with plugin)
- Webpack โ Via json5-loader
- Node.js โ Via json5 npm package
- Python โ Via pyjson5 package
- VS Code โ Syntax highlighting for .json5 files
Using JSON5 in Code
Converting JSON5 to JSON
When you need to use JSON5 files with tools that only accept standard JSON, you'll need to convert. The process strips:
- All comments (// and /* */)
- Trailing commas
- Single quotes โ double quotes
- Unquoted keys โ quoted keys
- Hex numbers โ decimal numbers
- Infinity/NaN โ null (or throws, depending on settings)
Real-World Example
Here's a typical JSON5 configuration file:
Try It Yourself
Want to format, validate, or convert JSON5? Use our free JSON5 Formatter & Converter. It parses JSON5 with all features, formats it beautifully, and can convert to standard JSON when needed.
For simpler files with just comments (like VS Code settings), try our JSONC to JSON Converter.