JSON5 Frequently Asked Questions

Frequently asked questions about JSON5 syntax, usage, and adoption.

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 features from ECMAScript 5.1 including comments, trailing commas, unquoted object keys, single-quoted strings, hexadecimal numbers, and more.

JSON5 is a superset of JSON, meaning every valid JSON file is automatically valid JSON5. This makes adoption simple - you can start with existing JSON files and gradually add JSON5 features as needed.

Is JSON5 backward compatible with JSON?

Yes, 100%. JSON5 is a strict superset of JSON. Every valid JSON document is also a valid JSON5 document. This means you can:

  • Rename your .json files to .json5 without any changes
  • Start using JSON5 features gradually
  • Mix JSON and JSON5 syntax in the same file

How do I add comments in JSON5?

JSON5 supports both single-line and multi-line comments, just like JavaScript:

// This is a single-line comment { name: 'my-app', // Inline comment /* This is a multi-line comment */ version: '1.0.0', }

What are trailing commas and why do they matter?

Trailing commas are commas after the last item in an array or object. In standard JSON, they cause a syntax error. In JSON5, they're allowed.

This matters because:

  • Cleaner git diffs - Adding a new item only shows one line changed
  • Easier editing - No need to fix commas when reordering items
  • Fewer errors - Copy-paste operations don't break syntax

How do I parse JSON5 in JavaScript/Node.js?

Use the official json5 npm package:

// Install: npm install json5 import JSON5 from 'json5'; // Parse JSON5 const obj = JSON5.parse(`{ name: 'app', // comment allowed version: '1.0', }`); // Stringify (outputs standard JSON) const json = JSON5.stringify(obj, null, 2);

Can I use JSON5 for package.json?

No, npm and Node.js require package.json to be standard JSON. However, you can use JSON5 for:

  • tsconfig.json - TypeScript supports comments (JSON5 subset)
  • babel.config.json5 - Babel has native JSON5 support
  • eslint.config.json5 - ESLint supports JSON5 configs
  • Custom config files - Any config you parse yourself

What's the difference between JSON5 and JSONC?

JSONC (JSON with Comments) only adds comment support to JSON. JSON5 includes comments plus many more features:

  • Trailing commas in arrays and objects
  • Unquoted object keys
  • Single-quoted strings
  • Multi-line strings
  • Hexadecimal numbers, Infinity, and NaN

If you only need comments, JSONC is simpler. If you want a more human-friendly format overall, JSON5 is the better choice.

Is JSON5 slower than JSON?

Yes, but typically it doesn't matter. Native JSON.parse() is faster because it's built into JavaScript engines. JSON5 parsing requires a JavaScript library.

For configuration files loaded once at startup, the difference is negligible (a few milliseconds). For high-frequency parsing (like API responses), stick with standard JSON.

Should I use .json5 or .json extension?

Use .json5 when:

  • You want editor syntax highlighting
  • You're using JSON5-specific features
  • You want to make it clear the file uses JSON5

Keep .json when:

  • The consuming tool expects .json
  • You're only using comments (tsconfig.json style)
  • Backward compatibility is important

Is JSON5 an official standard?

JSON5 is not an ECMA or IETF standard like JSON. However, it has:

  • A well-defined specification
  • A reference implementation with millions of weekly downloads
  • Wide adoption in popular tools (TypeScript, Babel, ESLint)

JSON5 has been stable since 2012 and is widely trusted for configuration files.

When should I NOT use JSON5?

Stick with standard JSON for:

  • API responses - Machine-to-machine communication
  • Database storage - Data that won't be hand-edited
  • Public interfaces - When consumers expect JSON
  • Performance-critical parsing - High-frequency operations

Use JSON5 for human-facing files like configuration, test fixtures, and localization.

How do I convert JSON5 to JSON?

Parse with JSON5, stringify with JSON:

import JSON5 from 'json5'; // JSON5 input (with comments, etc.) const json5String = `{ name: 'app', /* comment */ }`; // Parse as JSON5, output as JSON const obj = JSON5.parse(json5String); const jsonString = JSON.stringify(obj, null, 2); // Result: {"name": "app"}

You can also use online tools like transform.tools for quick conversions.

Still Have Questions?

Explore our learning resources or check out the official JSON5 documentation.