piapia123
en

JSON5 → JSON

Format

Everything runs locally in your browser — nothing is uploaded

Input
Drop a file here to load its contents
Output

Parse a JSON5 document into strict JSON. JSON5 is a superset of JSON: it adds comments (`//` and `/* */`), unquoted keys (including non-ASCII identifiers), single-quoted strings, trailing commas, hex numbers, a leading `+`, `.5` / `5.` forms, and `Infinity` and `NaN`. Config files all over the place use it (VS Code, Babel, parts of TypeScript and ESLint) while many tools accept only strict JSON. There is only one direction, and there is a reason: JSON is already a subset of JSON5, so “JSON → JSON5” is the identity transform. Offering it as an option would imply it does something else (add comments? switch to single quotes?), and it cannot. If you need that direction, a standard JSON document already *is* a valid JSON5 document — just use it. This is a complete implementation rather than a “good enough” subset — `\x41`, `\u{1F600}`, line continuations and `+Infinity` are all handled per spec, and errors come with a line and column. ⚠️ Two known conversion losses, both noted below: JSON cannot express `Infinity` or `NaN`, so they become `null`; and comments can never survive, because JSON has nowhere to put them.

Features

  • Comments: `//` line comments and `/* */` block comments, anywhere in the document
  • Unquoted keys, including non-ASCII identifiers and ones starting with `$` or `_`
  • Single-quoted strings (which can contain double quotes without escaping)
  • Trailing commas in objects, arrays and nested structures
  • Hex `0xFF`, a leading `+`, and the `.5` / `5.` forms
  • `Infinity`, `-Infinity` and `NaN` (JSON has none of them)
  • `\x41`, `\u{1F600}` and line continuations handled per spec
  • Parse errors name a line and column rather than saying “invalid format”
  • ⚠️ A `__proto__` key becomes an ordinary property and does not pollute the prototype
  • The output is strict JSON, readable by any tool that only accepts JSON

How to use

  1. Paste JSON5 — comments, unquoted keys and trailing commas are all fine
  2. The result updates as you type
  3. Choose an indent, or collapse it to one line
  4. Copy the result

FAQ

Why is there no “JSON to JSON5” direction?
Because it is the identity transform. JSON5 is a strict superset of JSON (that was the design goal), so any valid JSON document is already a valid JSON5 document; there is nothing to convert. As a button it would either do nothing (and look broken) or take stylistic liberties — stripping key quotes, switching to single quotes — and those are style choices a tool should not make for you.
Where did the comments go?
They are dropped, and they can only be dropped: JSON has no syntax that can carry a comment, and strict JSON forbids them outright. That is a difference between the formats, not a decision this implementation made. If those comments matter — explanatory notes, a commented-out flag — keep the original file around rather than treating it as a disposable intermediate.
Infinity and NaN became null — is that a bug?
No, though it is a real loss — JSON simply cannot represent them. `JSON.stringify(Infinity)` is `null` by definition of the language, and any tool emitting strict JSON behaves the same. JSON5 allowing `Infinity` / `NaN` is one of its extensions, and standard JSON has no syntax for it. If your data contains those values, what you need is an agreed convention (such as the string `"Infinity"`) shared with whatever consumes it — a converter cannot decide that on its own.
Is this a hand-written parser or a library?
Hand-written — for the opposite reason to the YAML and TOML tools here. Those two are hard because “the same thing can be written ten ways”, so a hand-rolled subset will eventually misread something silently, which is why they use a mature library. JSON5’s grammar is closed and frozen (1.0 in 2018, unchanged since) and amounts to comments, unquoted keys, single quotes and trailing commas on top of JSON, so a complete implementation is tractable. Correctness is anchored by a differential test: for any valid JSON input, this parser must agree with `JSON.parse` field for field.

Related tools