UTILS.
100% in-browser
{ }

JS Object to Strict JSON

Repair a loose JavaScript object literal — unquoted keys, single quotes, trailing commas, comments — into strict valid JSON, without eval.

— output appears here —

About this tool

The JS Object to Strict JSON tool repairs a loose JavaScript or JSON5-style object literal into strict, valid JSON. It is built on a hand-written tokenizer — it never uses eval or new Function — so it is safe under a strict Content Security Policy and safe to paste untrusted text into. Everything runs in your browser.

It accepts the things real JSON rejects: unquoted identifier keys, single-quoted strings, trailing commas before ] or }, // line and /* block */ comments, hexadecimal (0xFF), octal and binary literals, leading-plus and leading-dot numbers (+1, .5), and the values undefined, NaN, and Infinity. Keys are re-quoted with double quotes, strings are re-escaped correctly, comments and trailing commas are stripped, and numbers are normalized to plain JSON numbers. You choose how to treat undefined (convert to null or drop the key) and non-finite numbers (convert to null or raise an error), then the value is re-serialized with JSON.stringify at your chosen indent — 2 spaces, 4 spaces, tabs, or minified.

When the input cannot be parsed, the tool reports the first syntax error with its line and column so you can find the problem quickly. This complements a strict JSON formatter, which simply rejects loose input — here the goal is to salvage copied console output, config snippets, and hand-edited objects into JSON that any parser will accept.

Frequently asked questions

What loose syntax does it accept?
Unquoted keys, single-quoted strings, trailing commas, // and /* */ comments, hex/octal/binary numbers, leading-plus and leading-dot numbers, and the literals undefined, NaN, and Infinity — the common things that make copied JS objects invalid as JSON.
Does it use eval to parse?
No. It uses a hand-written tokenizer and recursive-descent parser, never eval or new Function, so it works under a strict Content Security Policy and is safe for untrusted input. It only ever produces data, never runs code.
How are undefined, NaN, and Infinity handled?
JSON has no such values. You choose: undefined can become null or have its key dropped, and NaN/Infinity can become null or raise an error. This keeps the output strictly valid JSON either way.
What happens when the input is invalid?
The parser stops at the first genuine syntax error and reports it with the line and column where it occurred, so you can locate and fix the offending character rather than guessing.

More tools