Skip to main content

JSON Dialect Detector

Tell whether a file is JSON, JSONC or JSON5 - and convert it to strict JSON.

Reviewed by · Last reviewed

What You Should Know

Paste a config file and this tool tells you which of the three JSON dialects it actually is. Plain JSON parses under RFC 8259. JSONC adds comments and trailing commas, and is what VS Code writes for tsconfig.json. JSON5 goes further, allowing unquoted keys, single quotes and hex numbers. The detector names every non-strict construct it finds, points at the line, and converts the document to strict JSON you can paste into JSON.parse.

Runs 100% in your browser - your data never leaves your device

Rate this tool
Be the first to rate

Frequently Asked Questions

What is the actual difference between JSON, JSONC and JSON5?

They are three grammars that produce nearly identical-looking files. Plain JSON is <a href="https://datatracker.ietf.org/doc/html/rfc8259">RFC 8259</a>: double-quoted keys and strings, decimal numbers, no comments, no trailing commas. JSONC is that plus <code>//</code> and <code>/* */</code> comments and trailing commas - it is the dialect Visual Studio Code reads for <code>tsconfig.json</code>, <code>settings.json</code> and <code>launch.json</code>. JSON5 goes furthest: unquoted identifier keys, single-quoted strings, hexadecimal numbers, leading and trailing decimal points, <code>Infinity</code> and <code>NaN</code>, and multi-line strings. Each is a strict superset of the one before it.

Why does my .json file fail JSON.parse when my editor shows no errors?

Because your editor is almost certainly parsing it as JSONC while <code>JSON.parse</code> parses it as strict JSON. VS Code ships a JSONC reader for the well-known config filenames, so a comment or a trailing comma in <code>tsconfig.json</code> looks completely fine in the editor and throws the moment a Node script reads the same bytes. The file extension is <code>.json</code> in both cases, which is what makes this confusing - the extension tells you nothing about which parser will be used.

Does this tool send my config file anywhere?

No. The parser is plain TypeScript bundled into the page and it runs on the page thread. There is no <code>fetch</code> call, no upload, and no service worker involved, so a config containing internal hostnames or keys never leaves the tab. You can confirm it by opening the Network tab in DevTools before pasting, or by loading the page once and then going offline.

Why is a comma before the closing brace such a common mistake?

Because most languages that developers move between allow it. Python, JavaScript array and object literals, Rust, Go and modern C all tolerate a trailing comma, precisely so that adding a line to a list produces a one-line diff. JSON deliberately does not, which means reordering or appending a key in a strict JSON file always dirties two lines instead of one. That friction is why JSONC exists at all.

What happens to Infinity and NaN when converting JSON5 to strict JSON?

They become <code>null</code>, and the tool warns you when that happens. Strict JSON has no production for non-finite numbers, and JavaScript's <code>JSON.stringify</code> resolves them to <code>null</code> rather than failing. If those values are meaningful in your data, encode them explicitly as strings such as <code>"Infinity"</code> or use a sentinel number your consumer understands, then convert on the way back in.

Which parser should I use for each dialect in Node?

For plain JSON, the built-in <code>JSON.parse</code>. For JSONC, either <code>jsonc-parser</code> (the package VS Code itself uses) or <code>strip-json-comments</code> followed by <code>JSON.parse</code> - the former is preferable because it also handles trailing commas and reports error positions. For JSON5, the <code>json5</code> package, whose <code>JSON5.parse</code> is a drop-in replacement. Never write your own comment-stripping regex: a <code>//</code> inside a string value such as a URL will be mangled by it.

Learn more

Related tools

More Developer Tools

Support ZeroUtil