JSON to JavaScript Object
Convert JSON into a JavaScript object literal — with unquoted keys where safe — ready to paste directly into code.
Use the tool ↓Your data is processed locally in your browser and is not uploaded to our servers.
About this tool
JSON and a JavaScript object literal look nearly identical, and for good reason — JSON's syntax was deliberately modeled on JavaScript's object and array literals. But they're not quite the same thing: JSON requires every key to be double-quoted, while idiomatic JavaScript typically leaves keys unquoted when they're valid identifiers, reserving quotes for keys that actually need them (ones with spaces, hyphens, or that start with a digit). Pasting raw JSON directly into a JS file works fine functionally, but it reads as slightly foreign — not quite how a developer would have written the same object by hand.
This tool closes that small gap: it converts JSON into the object literal syntax you'd actually write in a JavaScript file, unquoting keys wherever it's syntactically safe to do so and keeping quotes only where JavaScript requires them. The result is assignable to a variable with a name you choose, ready to paste directly into a script, a test fixture, or a mock data file without any manual cleanup.
Type conversion in this direction is the easy part — JSON's true/false/null are already valid JavaScript, and every JSON value maps onto its JavaScript equivalent without any special handling needed, unlike the JSON-to-Python direction where boolean and null literals genuinely need translating. What this tool adds over just pasting the JSON as-is is purely the readability layer: sensible indentation and idiomatic unquoted keys.
One thing this tool deliberately does not do: execute the generated code, or any code you paste. It's a text transformation only — your JSON is parsed and re-serialized as JavaScript syntax, nothing more. Everything runs locally in your browser; nothing you paste is sent anywhere.
How to use it
Paste your JSON
Any valid JSON object or array works.
Set a variable name
Choose the name the generated object will be assigned to.
Copy or download
Paste directly into a .js file, or download it ready to use.
Example
{"name":"John","age":30,"active":true}const data = {
name: "John",
age: 30,
active: true
};Common use cases
Creating test fixtures
Turn a JSON example into a JS mock object for tests.
Hardcoding sample data
Paste an API response into a component as static placeholder data.
Building config objects
Convert a JSON config into an idiomatic JS config module.
Quick prototyping
Get sample data into a script fast without hand-editing syntax.
Teaching JS object syntax
Show how JSON maps onto idiomatic JavaScript object literals.
Seeding in-memory data
Convert JSON into a constant used by a small script or demo.