JSON to JavaScript Object
Paste JSON and get a JavaScript object literal that looks like hand-written code: keys without quotes wherever they are valid identifiers, single or double quotes for strings, trailing commas, and indentation that matches your style. Wrap it as a const, an ES module default export or a CommonJS export, and optionally freeze it. Strings are escaped correctly for the chosen quote style.
- Runs in your browser
- No sign-up
- Free to use
How to use JSON to JavaScript Object
- Paste or load JSON.
- Choose the declaration, quote style and indentation.
- Toggle trailing commas, quoted keys or Object.freeze.
- Copy the code or download data.js.
JSON to JavaScript Object features
Idiomatic output
Unquoted identifier keys, quoted only where needed.
Your style
Single, double or backtick quotes; 2 or 4 spaces, tabs or one line.
Module formats
const, export default or module.exports.
Correct escaping
Quotes, backslashes, line breaks and </script> handled for each quote style.
Object.freeze
Optional, with a note that freezing is shallow.
Precision check
Warns about integers beyond JavaScript’s safe range.
When to use JSON to JavaScript Object
- Turning an API response into a test fixture or mock.
- Moving a JSON config into a JavaScript or TypeScript module.
- Matching a codebase’s Prettier style for single quotes and trailing commas.
- Embedding seed data in a front-end component.
JSON to JavaScript Object FAQ
Is JSON not already JavaScript?
Almost: valid JSON is a valid JavaScript expression. But code style guides usually prefer unquoted keys, single quotes and trailing commas, and linters flag JSON pasted as-is. This tool produces the idiomatic form.
Why are some keys still quoted?
Keys such as "content-type" or "2nd" are not valid identifiers, so they must stay quoted. Reserved words like class can be used unquoted as property names in modern JavaScript.
Does it change the data?
No. Values, types and key order stay the same; only the notation changes.
What does Object.freeze do?
It makes the top-level object read-only. Nested objects are not frozen; that requires a deep-freeze helper.
Can I convert JavaScript objects back to JSON?
Yes, with the JavaScript JSON Stringify Tool, which reads object literals safely without running them.
Is anything uploaded?
No. The conversion happens in your browser.
From JSON to JavaScript source
Every JSON document is also a valid JavaScript expression, which makes it tempting to paste JSON straight into code. The result works but looks out of place: every key wrapped in double quotes, no trailing commas, and a quote style that differs from the rest of the project. Linters and formatters then complain, and reviewers have to read past the noise.
This converter rewrites the notation without touching the data. Keys that are valid identifiers lose their quotes, numeric keys stay bare, and anything else, such as keys with hyphens or spaces, keeps quotes in your chosen style. String values are re-escaped for that style, so a single quote inside a single-quoted string is escaped and a template literal never interpolates ${ sequences from the data.
Formatting choices follow common conventions. Two-space indentation with single quotes and trailing commas matches the defaults of many style guides and Prettier configurations, while tabs, four spaces or a compact single line suit other projects. Trailing commas make later diffs cleaner because adding an entry changes only one line.
The declaration options cover the usual destinations. A const declaration fits inside an existing file, export default produces an ES module that bundlers and modern browsers understand, and module.exports produces a CommonJS module for Node.js scripts and older tooling. Object.freeze can wrap the value to signal that it should not be modified at run time.
One limitation comes from JavaScript itself. Numbers are 64-bit floating point, so integers above 9,007,199,254,740,991 cannot be represented exactly, and IDs from some databases exceed that. The converter warns when the JSON contains such numbers; in that case keep them as strings or use BigInt in your code.