โ† Home ยท Blog

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:

{ // This is a single-line comment name: "MyApp", /* This is a multi-line comment */ version: 1.0, }

2. Trailing Commas

Add commas after the last item without errors:

{ features: [ "comments", "trailing commas", "unquoted keys", // โ† No error! ], }

3. Unquoted Object Keys

Keys can be unquoted if they're valid identifiers:

{ name: "value", // Valid: simple identifier $price: 99, // Valid: starts with $ _private: true, // Valid: starts with _ "with-dash": 1, // Must quote: contains hyphen "123num": 2, // Must quote: starts with number }

4. Single-Quoted Strings

Use single or double quotes interchangeably:

{ single: 'Hello, World!', double: "Hello, World!", mixed: 'He said "Hello"', // Easier escaping }

5. Hexadecimal Numbers

Hex notation for numbers (great for colors):

{ primaryColor: 0x6C5CE7, permissions: 0x755, maxValue: 0xFFFFFFFF, }

6. Special Numeric Values

Infinity and NaN are valid:

{ timeout: Infinity, negativeInfinity: -Infinity, notANumber: NaN, positive: +5, // Explicit positive sign }

7. Leading/Trailing Decimal Points

Numbers can start or end with a decimal:

{ half: .5, // Same as 0.5 five: 5., // Same as 5.0 tiny: .001, }

8. Multi-line Strings

Strings can span multiple lines using backslash escapes:

{ longText: "This is a very long string \ that spans multiple lines \ for better readability.", }

JSON vs JSONC vs JSON5

These three formats are often confused. Here's how they compare:

FeatureJSONJSONCJSON5
CommentsโŒโœ…โœ…
Trailing commasโŒโœ…โœ…
Unquoted keysโŒโŒโœ…
Single quotesโŒโŒโœ…
Hex numbersโŒโŒโœ…
Infinity/NaNโŒโŒโœ…
Multi-line stringsโŒโŒโœ…
Leading/trailing decimalsโŒโŒโœ…
StandardRFC 8259VS Codejson5.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

// JavaScript/Node.js const JSON5 = require('json5'); // Parse JSON5 const config = JSON5.parse(`{ // Database settings host: 'localhost', port: 5432, }`); // Stringify (outputs standard JSON by default) JSON5.stringify(config); // Stringify as JSON5 (preserves formatting) JSON5.stringify(config, null, 2);
# Python import pyjson5 # Parse JSON5 config = pyjson5.load(open('config.json5')) # Convert to standard JSON import json json.dumps(config)

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:

{ // Application Configuration name: 'my-awesome-app', version: '2.0.0', /* Server Settings These can be overridden by environment variables */ server: { host: 'localhost', port: 3000, timeout: Infinity, // Never timeout in development }, // Feature flags features: { darkMode: true, analytics: false, // Disabled for now experimental: { newUI: true, aiAssistant: false, }, }, // Allowed origins for CORS cors: [ 'http://localhost:3000', 'https://example.com', 'https://staging.example.com', // Trailing comma OK ], }

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.

Related Tools

Work with JSON5 and related formats:

More Articles

What is JSON โ€” A Complete Guide

JSON vs XML vs YAML โ€” Comparison

Common JSON Errors and How to Fix Them

How to Format JSON