JSON5 Decoder

Convert JSON5 (with comments, trailing commas, etc.) to strict JSON.

Open tool

Overview

The JSON5 decoder takes a JSON5 document — JSON's friendlier cousin that allows comments, trailing commas, single-quoted strings, and unquoted keys — and converts it to strict, RFC 8259-compliant JSON.

JSON5 shows up wherever humans hand-write JSON: VS Code settings, Babel and Webpack configs, several Rust and Python tools. Developers preparing JSON5 for a strict consumer, building tooling that needs RFC-compliant output, or just curious about what their config really means use a json5 to json converter to bridge the gap.

How it works

JSON5 is a superset of JSON that allows: single-line // and block /* */ comments, trailing commas in objects and arrays, unquoted object keys (when they're valid ECMAScript identifiers), single-quoted strings, multi-line string continuations, hex literals (0xFF), leading or trailing decimals (.5, 5.), positive sign on numbers (+1), and Infinity / NaN literals.

The decoder parses all of these extensions, drops comments, normalises strings to double quotes, removes trailing commas, and emits valid JSON. Numbers are kept in their canonical numeric form — hex and exotic floats are rendered as decimal — so the output passes any strict JSON parser.

Examples

// JSON5 input:
{
  // top-level config
  name: 'Alice',
  age: 30,
  hexValue: 0xFF,
  tags: ['admin', 'ops',],
}
JSON output:
{
  "name": "Alice",
  "age": 30,
  "hexValue": 255,
  "tags": ["admin", "ops"]
}
// JSON5 with Infinity:
{ "max": Infinity }
JSON: { "max": null }
// Note: JSON has no Infinity literal; converted to null with a warning.

FAQ

Why doesn't JSON have comments?

The JSON specification was designed for machine interchange; comments were intentionally left out so parsers don't have to handle them. JSON5 added them back for human-edited config files where annotations are valuable.

Are comments preserved as anything in the output?

No — comments are dropped because strict JSON has no place to put them. If you need them, keep the JSON5 source and run the decoder only for downstream tools.

What about Infinity and NaN?

JSON can't represent these. The decoder converts them to null (and emits a warning) since that's the safest fallback every consumer can handle.

Try JSON5 Decoder

An unhandled error has occurred. Reload ×