JS Object to JSON Converter
Turn a JavaScript object literal into valid JSON: unquoted keys, single quotes, trailing commas and comments all handled.
JSON output
Paste a JavaScript object above, or tap Load sample to see how it works.
Changes made to fit JSON
How it works
Paste a JavaScript object literal and this converter reads it with a hand-written
best-effort parser that runs entirely in your browser, then re-serialises the result as
JSON. It understands the everyday things JSON forbids: unquoted property names, single
quotes and backtick strings, trailing commas, // and /* */
comments, hex, binary, octal and underscore-separated numbers
(0x1f90, 5_000_000), undefined,
NaN, Infinity and BigInt literals such as 123n.
A leading const x =, module.exports = or
export default and a trailing semicolon are stripped for you.
The output is plain JSON as defined by RFC 8259 / ECMA-404. The input
grammar is the ECMAScript object-literal subset also covered by JSON5, and this is a
translator rather than a full JavaScript engine: anything whose value only exists at
runtime is rejected with a line and column rather than guessed at, including function
values, regular expression literals, new Date(...) and other constructor
calls, spread syntax, computed keys and template literals containing
${โฆ}. Where a JavaScript value has no JSON equivalent the
converter still has to approximate: undefined, NaN and
Infinity become null, comments are dropped, duplicate keys
collapse to the last one and BigInt values above 253 − 1 lose
precision. Every approximation it applied is listed under the output, so nothing changes
silently.
Nothing is uploaded. The parsing and formatting happen in JavaScript on your device, and
the code is never evaluated โ no eval, no new Function โ so
pasting a config object with hostnames, keys or internal URLs is safe.
Frequently asked questions
How do I convert a JavaScript object to JSON?
Paste the object literal into the input box and the JSON appears instantly below it. Unquoted property names, single-quoted and backtick strings, trailing commas, // and /* */ comments, hex and underscore-separated numbers and a leading const x = or module.exports = are all accepted. Pick 2-space, 4-space, tab or minified output, then use Copy JSON or Download .json.
Does this tool run eval on my code?
No. The object is read by a hand-written parser, never executed, so there is no eval and no new Function anywhere on the page. Everything runs in your browser, so config objects containing hostnames, internal URLs or keys are never uploaded or logged.
What cannot be converted to JSON?
Anything whose value only exists when the code runs: function values, regular expression literals, new Date(...) and other constructor calls, spread syntax, computed keys and template literals with ${} interpolation. Those are rejected with a line and column rather than guessed at. Values with no JSON equivalent are approximated instead, so undefined, NaN and Infinity become null, comments are dropped and duplicate keys collapse to the last one. Every approximation applied is listed under the output.