JSON5 Formatter & Validator

Format and validate JSON5 with a full parser written for this tool — comments, unquoted keys, trailing commas, hex numbers and multiline strings all understood, every JSON5-only feature your file uses counted in a strictness report, and an explicit convert mode that turns it into strict JSON with NaN and Infinity reported as they become null. Your input is never auto-saved: JSON5 files are configuration, and configuration carries secrets. Free, no sign-up — runs locally in your browser.

…or drop a file onto the panel. Files are read locally and never uploaded.

Configuration files often deserve discretion, so this tool deliberately does not auto-save your input — paste, format, copy, and it is gone when you leave.

JSON5 fails politely — in someone else's parser

A JSON5 config file usually looks completely reasonable right up to the moment a strict parser meets it: the comment you left for your future self, the trailing comma from the last edit, the key you didn't bother quoting. JSON.parse's answer to all of it is the same unhelpful position-less shrug. This tool parses JSON5 with a parser written for it — the full feature grammar, not a regex cleanup — and answers three distinct questions properly: is it valid (and if not, exactly where and why not), what does it rely on (the strictness report: every JSON5-only feature, counted), and what would it be as strict JSON (an explicit conversion, with every value JSON cannot express reported as it becomes null).

How to use this tool

  1. Paste the JSON5, upload a .json5 file, or drop one onto the panel — hand-written configs, .babelrc files, and tool settings are the home crowd.
  2. Press Format JSON5 for canonical layout plus the strictness report. Validate only gives the verdict and the report without producing a reformatted copy.
  3. Press Convert to strict JSON when the consumer is a strict parser: keys become double-quoted strings, numbers are written canonically, and NaN / Infinity become null — each such change listed in the report under the result.
  4. On an error, start from the position: the message gives line and column and names the grammar rule that was broken.
  5. Use the two sample buttons to compare: the valid sample uses most of the dialect; the broken one pairs a leading-zero number with an array hole, and the error points at the first.

What the parser accepts — and refuses

Accepted, as JSON5 specifies: line and block comments; unquoted keys that are valid identifiers (including reserved words and literal names — { NaN: 1 } is a legal object); single- and double-quoted strings with the full escape grammar (\xHH, \uXXXX, line continuations, identity escapes); trailing commas in objects and arrays; hex integers; leading and trailing decimal points; a leading +; and the non-finite values NaN and ±Infinity. Refused, with positions: array holes, leading-zero decimals, octal escapes, a number cut off mid-exponent, an unterminated string or comment, and content trailing the document's value. Judgement calls, reported: duplicate keys are last-wins and named; comments are counted, and formatting does not re-print them.

The formatter's side of the bargain

In exchange for that strictness, formatting touches nothing it does not have to. Your 0x1F90 is still 0x1F90 afterwards, your .75 still .75, your unquoted keys still unquoted — the spellings in a hand-written config are often deliberate (a hex port, a ratio), and a formatter that canonicalises them away is editing your file, not tidying it. What changes is layout: indentation and line breaks. Canonicalisation exists, deliberately, in exactly one place — Convert to strict JSON, where changing spellings is the entire point and every change is reported.

Frequently asked questions

What is JSON5, and why does my file need a special tool?

JSON5 is the dialect of JSON that humans actually write in configuration files: comments, unquoted keys, single-quoted strings, trailing commas, hex numbers, values like .5, 5., +Infinity and NaN. It is a formal extension of ECMAScript 5 object literals, and tools across the ecosystem (Babel's config among them) read it. Strict JSON parsers reject every one of those features, which is the daily friction this tool exists for: paste the file here and you get either clean JSON5 back, a verdict on what's wrong with it, or strict JSON with every conversion reported.

What is the strictness report?

The list, with counts, of every JSON5-only feature your document uses: comments, unquoted keys, single-quoted strings, trailing commas, hex numbers, leading + signs, .5 and 5. style numbers, Infinity, NaN, strings continued across lines, \x escapes. It is the precise answer to 'why won't JSON.parse take this file?' — each entry is a construct strict JSON forbids. If the report is empty, your document was strict JSON all along.

Does formatting change my values or spellings?

No. Formatting rearranges whitespace only: objects and arrays expand one entry per line at your chosen indent. Number spellings are preserved exactly (0x1F90 stays 0x1F90, 5. stays 5., +Infinity keeps its sign), and each key keeps its original quoted-ness — an unquoted key stays unquoted, a quoted one stays quoted. Strings are re-encoded in canonical double-quoted form: a single-quoted string's content is data and survives untouched; its quote style is presentation and normalises. Comments are consumed by parsing and are not re-printed — if you need them preserved verbatim, formatting JSON5 is the wrong operation and the page would rather say so than drop them silently (they are counted in the report).

How does Convert to JSON handle NaN and Infinity?

JSON cannot express them, so they become null — never silently. The report names every value that was nulled (NaN, +Infinity, -Infinity, with duplicates collapsed), counts every number that had to be rewritten canonically (0x1F90 becomes 8080, .75 becomes 0.75) with examples, and the feature report explains why the file needed converting at all. If nulling a value would be wrong for your data, the report tells you where it happened so you can fix the source instead.

Which JSON5-looking things are actually errors here?

Array holes — [1, , 2] is legal JavaScript but not JSON5, and is refused rather than guessed at. Leading-zero decimals like 012, which the ES5 grammar JSON5 inherits treats as a mistake, not a value. Octal escapes (\01) in strings. A lone . or a sign with no number after it. Duplicate keys are the judgement call in the other direction: they are accepted, the last value wins (what JSON.parse does with duplicated keys in JSON, and what JSON5's own reference parser does), and every duplicate is named in the report so the shadowing is visible.

Is my configuration uploaded or saved?

Neither, by design. Everything runs as local JavaScript in your browser tab, and unlike most tools on this site this one deliberately does not auto-save its input — JSON5 files are configuration (.babelrc, tsconfig-flavoured files, service settings), and configuration carries API endpoints, feature flags and occasionally worse. Paste, format, copy, and it is gone when you leave; that is also why the site says the same on the TOML tool, whose files carry the same risks.

Related tools