Turn a JavaScript object literal into valid JSON

Console output, fixtures and config snippets quote keys only sometimes and use single quotes. Strict JSON parsers reject all of it — this rewrites it properly.

Tools used in this guide

The job

You copied {a: 1, b: 'x'} out of a console.log and JSON.parse refuses it. Unquoted keys, single quotes, trailing commas and undefined are all legal JavaScript and all illegal JSON — converting by hand is where mistakes creep in.

Paste the literal

Paste the object or array literal; the parser handles unquoted keys, single and template-free string quotes, comments, trailing commas, and numeric forms like .5 or 0x1F. Output is strict, double-quoted, pretty-printed JSON.

  • undefined entries are dropped, matching what JSON.stringify would produce.
  • NaN and Infinity have no JSON representation and are reported rather than guessed.

Not an evaluator

The input is parsed as a literal, not executed — functions, spread syntax, variables and computed keys are rejected. That's deliberate: it means pasting code can never run anything. Limit: 1,000,000 characters.