JSON ↔ JavaScript Object Converter

Both directions. Client-side. Handles unquotable keys, trailing commas, and comments correctly.

Both directions, in your browser. Paste JSON to get a JS object literal, or paste a JS object to get valid JSON. Nothing is sent to a server. How to use ↓·Shortcuts ↓
Paste JSON, get a JavaScript object literal.
Indent:Quotes:
Samples:
JSON Input
JavaScript Output
Output will appear here.
Input: 0 chars · 0 bytesOutput: 0 chars · 0 bytes

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 + KFocus the input pane
Cmd / Ctrl + EnterCopy 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.

Frequently asked questions

What is the difference between JSON and a JavaScript object?
JSON is a strict text format for data exchange. A JavaScript object is a runtime value in JS code. JSON requires double-quoted keys and strings, forbids trailing commas and comments, and only supports six data types. JS object literals are more permissive: unquoted keys, single or double quotes, trailing commas, comments, and richer types including functions and undefined.
Why did my keys stay quoted after conversion?
Only keys that are valid JavaScript identifiers get unquoted. Keys with spaces, dashes, digits at the start, or reserved words like class or default must stay quoted to produce valid JavaScript.
Does the tool send my data anywhere?
No. All conversion happens in your browser. The input never leaves the page.
Can I paste a full const declaration?
Yes. On JS to JSON, a leading const/let/var declaration and trailing semicolon are stripped before parsing.
What happens if my JS object has a function or undefined?
Those are not valid JSON. The tool rejects them with a clear error rather than producing broken output.
Does it handle comments in JS input?
Yes. Both single-line // and block /* ... */ comments are stripped before parsing.