JSON ↔ JavaScript Object Converter
Both directions. Client-side. Handles unquotable keys, trailing commas, and comments correctly.
How to use
Pick a direction with the tabs at the top — JSON → JS or JS → JSON. Paste your input into the left pane. The converted output appears on the right as you type.
Use the options row to control indent size, quote style (JSON→JS only), whether to unquote object keys, add trailing commas, or prefix the output with const data = .
Copy the output with the Copy button, or download it as a .js / .json file.
Keyboard shortcuts
Three shortcuts are wired on this tool:
| Cmd / Ctrl + K | Focus the input pane |
| Cmd / Ctrl + Enter | Copy output to clipboard |
| Cmd / Ctrl + / | Toggle between JSON→JS and JS→JSON |
When to use it
JSON is a strict data-interchange format. A JavaScript object literal is what you write in code. They look similar but differ in ways that matter:
- JSON requires double-quoted keys and strings. JS accepts unquoted keys and single quotes.
- JSON forbids trailing commas. JS allows them.
- JSON has no comments. JS does.
- JSON only supports strings, numbers, booleans, null, arrays, and objects. JS has
undefined, functions, dates, and more.
Convert JSON → JS when you want to paste API response data straight into your source as a literal. Convert JS → JSON when you have a JS object literal (from a config file, a mock, a snippet) and need valid JSON to send over the wire or drop into a .json file.
Options
Indent — 2 spaces (default), 4 spaces, or a tab character.
Quotes (JSON→JS only) — single quotes (JS convention) or double quotes. Strings and unquotable keys use the chosen style.
Unquote keys (JSON→JS only) — strips quotes from keys that are valid JS identifiers. Keys with spaces, digits at the start, dashes, or reserved words stay quoted. This produces valid JS.
Trailing commas (JSON→JS only) — adds a comma after the last item in objects and arrays. Legal in JS, invalid in JSON.
const prefix (JSON→JS only) — wraps the output as const data = {...}; so it's a full statement.
Format-specific gotchas
Not every key can be unquoted. A key like "first name", "123id", or "class" (a reserved word) must stay quoted to be valid JS. The tool handles this automatically — it only unquotes keys that match /^[A-Za-z_$][A-Za-z0-9_$]*/ and aren't reserved words.
JS-only values are rejected on JS → JSON. undefined, functions, NaN, and Infinity aren't valid JSON. The tool surfaces a clear error rather than producing broken output.
Comments are stripped. On JS → JSON, both // and /* ... */ comments are stripped before parsing. The output is comment-free.
const/let/var declarations are unwrapped. Paste const user = {...} and the tool strips the declaration and semicolon before parsing the object literal.
Privacy
Everything runs in your browser. Your JSON and JS input never leave the page — no server, no logging, no analytics on the content.