JS Object ↔ JSON
Convert a JavaScript object literal ({name: 'Alice'}) to strict JSON — or strict JSON back into a tidy JS literal with unquoted keys.
JS → JSON evaluates the input as a JS expression — only use on your own data.
How to use
- Paste your JS object literal or JSON.
- Pick the direction — JS → JSON wraps values strictly; JSON → JS unquotes identifier keys and prefers single quotes.
- Copy the output. Indent stays consistent.
About this tool
ShowHide
Accepts the loose syntax you write in actual JS: unquoted identifier keys, single quotes, trailing commas, line comments. Emits canonical JSON (or, in the reverse direction, a clean JS literal that matches what you'd type by hand). Useful for turning copied dev-console output into something a JSON parser will accept, or for prettifying API responses for inclusion in source code.
Parsing goes through JSON5 rather than new Function, which is the difference between a converter and an arbitrary code execution hole. Handing pasted text to the JavaScript engine would run whatever was in it, and object literals copied from a console are exactly the kind of text people paste without reading. The trade-off is that only data survives: a function, a new Date(...), a regular expression literal or a computed key is a parse error here rather than being evaluated into something else.
JSON5 also accepts values JSON has no way to express. NaN, Infinity, hexadecimal numbers like 0xFF and leading-decimal forms like .5 all parse, but JSON has no syntax for the first two, so they come back as null and the round trip is not always lossless. Numbers are another quiet edge: values beyond the range of a double lose precision on the way through, which is why a 19-digit identifier arrives back subtly changed. Keep long IDs as strings.
In the JS direction, keys that are valid identifiers are left unquoted and everything else is quoted in the style you pick. That output is a literal, not a statement, so assigning it needs the usual wrapper, and pasting a bare object at the start of a line makes the parser read the braces as a block.
Comments are dropped. They are not part of the data model on either side, so a heavily annotated config comes back clean but bare.
Frequently asked questions
How is it parsed?
JS → JSON is read by a JSON5 parser inside the page — the superset of JSON that allows unquoted keys, single quotes, trailing commas and comments. Nothing you paste is executed: an expression, a function call or a new Date() is a parse error, not code that runs.
What about functions, dates, or RegExps?
JSON can only carry strings, numbers, booleans, null, arrays, and plain objects. The converter rejects anything else with an explicit error rather than silently dropping it like JSON.stringify would.
Why prefer single quotes for JS output?
It matches the prevailing style in modern JS codebases (and is what Prettier emits by default). Flip the toggle if you'd rather see double quotes.
Why does JSON refuse things JavaScript accepts?
Because JSON is a data interchange format rather than a language: it was deliberately kept to what every implementation can agree on. No comments, no trailing commas, no single quotes, no unquoted keys, no undefined and no NaN or Infinity. Every one of those exists in JavaScript for the convenience of people writing code, and every one of them would need a rule that parsers in other languages might read differently.
Can I paste console output straight in?
Usually, but read the result. What a console prints is a rendering of an object rather than its source: long arrays are abbreviated, class instances show a constructor name, getters may print their computed value, and circular references appear as a placeholder. Anything abbreviated by the console is genuinely missing from the text you copied — the conversion cannot restore it.
Related tools
CSS to JS Style Object Converter
Convert a CSS declaration block into a React/JS inline style object, in your browser.
Developer
XML ↔ JSON Converter
Convert XML to JSON and back, with full attribute support, configurable attribute prefix and text key.
Convert
String Escape Converter
Escape a string for 10 contexts at once — JavaScript, JSON, HTML entities, URL, SQL, regex, Bash (single/double quote), C string, Unicode \u escapes.
Developer
JSON ↔ YAML Converter
Convert JSON to YAML or YAML to JSON — pick the indent and copy the result.
Convert
CSV → HTML / Markdown / JSON Table
Convert CSV to an HTML <table>, a Markdown table, or a JSON array of objects — auto-detects the delimiter.
Convert
Fixed-Width Text Parser to CSV / JSON
Split fixed-width / fixed-column text into fields by column widths and export as CSV or JSON, in your browser.
Convert