Loading comparison...
Loading comparison...
JSON5 is an extension of JSON that adds features developers have long wished for: comments, trailing commas, unquoted keys, and multi-line strings. It is designed to be a more human-friendly superset of JSON.
| Feature | JSON | JSON5 |
|---|---|---|
| Comments | Not supported | Supported (// and /* */) |
| Trailing commas | Not allowed | Allowed |
| Unquoted keys | Not allowed | Allowed (if valid identifier) |
| Single quotes | Not allowed | Allowed for strings |
| Multi-line strings | Not allowed | Allowed (backslash continuation) |
| Infinity/NaN | Not allowed | Supported |
| Hex numbers | Not allowed | Supported (0xFF) |
| Compatibility | Universal | Needs JSON5 parser |
| Primary ecosystem | Everything | Config files (Babel, Next.js, VS Code) |
Choose standard JSON when interoperability is critical. Every language, tool, and API speaks JSON natively. Use it for data exchange, API responses, and any file that machines read more often than humans. The strict syntax also prevents ambiguity.
Choose JSON5 for configuration files where developers need to add comments explaining settings, use trailing commas for cleaner diffs, or include special values like Infinity. JSON5 is commonly used in Babel configs, TypeScript tsconfig extensions, and VS Code settings.
Drop or paste one JSON file and one JSON5 file to see a structural diff
JSON5 is a strict superset of JSON — every valid JSON file is valid JSON5. Converting JSON5 to JSON strips comments, removes trailing commas, quotes all keys, and replaces single quotes with double quotes. Infinity and NaN have no JSON equivalent. The json5 npm package handles bidirectional conversion.
Douglas Crockford popularized JSON (JavaScript Object Notation) in the early 2000s as a lightweight data interchange format, and it was formalized as ECMA-404 in 2013 and RFC 8259 in 2017. Despite its name, JSON is language-independent and has become the dominant format for data exchange across the entire software industry. Every major web API — from REST services to GraphQL responses — uses JSON as its primary serialization format. The structure is built on two universal data constructs: ordered lists (arrays) and key-value maps (objects), with strings, numbers, booleans, and null as primitive values. This simplicity enables native parsing support in virtually every programming language. JSON's tree structure — with nested objects and arrays forming a hierarchical document — makes it ideal for representing complex data relationships while remaining human-readable.
Configuration files across the JavaScript ecosystem use JSON extensively: package.json for Node.js projects, tsconfig.json for TypeScript, and settings files for VS Code, ESLint, and Prettier. JSON Schema provides a vocabulary for annotating and validating JSON documents, enabling automated testing of API contracts. NoSQL databases like MongoDB, CouchDB, and Firebase store documents in JSON-like formats, and PostgreSQL includes native JSON and JSONB column types. Tools like jq enable command-line JSON processing, while JSON Patch (RFC 6902) and JSON Merge Patch (RFC 7396) define standardized approaches for describing modifications to JSON documents. The format's ubiquity means that JSON comparison is one of the most frequently performed diff operations in software development.
Jordan Tucker created JSON5 in 2012 to address the friction developers experience when writing JSON by hand, extending the format with features borrowed from ECMAScript 5.1 syntax. JSON5 allows single-line and multi-line comments, trailing commas in objects and arrays, unquoted object keys that are valid identifiers, single-quoted strings, multi-line strings, hexadecimal numbers, leading and trailing decimal points, positive and negative Infinity, NaN, and explicit positive sign on numbers. These additions make JSON5 significantly more ergonomic for configuration files that humans read and edit frequently, while maintaining a clear upgrade path from standard JSON — every valid JSON document is also valid JSON5. The format is used by several prominent development tools: Babel uses json5 for its configuration, and many VS Code extensions accept JSON5 configuration files.
The json5 npm package provides a drop-in replacement for JSON.parse() and JSON.stringify(), and implementations exist for Python, Java, Go, Rust, and other languages. JSON5's tree structure mirrors JSON exactly — objects and arrays form a nested hierarchy — with the same data types plus the numeric extensions. The specification is intentionally conservative, adding only features that ECMAScript 5.1 already supports for object and array literals, ensuring that the syntax is familiar to JavaScript developers. While JSON5 has not achieved the universal adoption of standard JSON, it occupies a valuable niche for configuration files where comments explain settings, trailing commas simplify diff-friendly editing, and human readability takes priority over strict machine parseability.