JavaScript Object to JSON Converter
Converts a JavaScript object literal into valid, formatted JSON.
Loading the tool…
How to use this tool
- Paste the object or array literal — trailing commas, single quotes and comments are all fine.
- Set the indent, or use 0 to get the JSON on a single line.
- Select Convert to JSON.
- Check the note above the result if your input contained functions or undefined values — JSON cannot carry those.
What javascript object to json does
A JavaScript object literal and a JSON document look similar enough that people paste one where the other is expected and then spend ten minutes on the parse error. JSON requires double-quoted keys, double-quoted strings, no trailing commas, no comments and no expressions. An object literal allows all of those. Hand-fixing the difference on a large object is exactly the kind of edit that introduces a typo.
This page evaluates the literal in the same isolated worker the sandbox uses — no network, no access to this page — and then serialises the value as JSON. That means trailing commas, single quotes, unquoted keys, comments and computed values like `1000 * 60` are all handled, because the language handles them. It also means the conversion is honest about its limits: JSON has no representation for a function, for undefined, or for a symbol, so if the input contains any of those the result says which were dropped rather than quietly losing them.