Convert JSON into a JavaScript object literal — identifier keys unquoted, your choice of quote style, optional trailing commas and declaration prefix. Ready to paste into code.
Show calculation steps
Processed privately in your browser — nothing you paste is uploaded, logged or stored.
JSON that looks like it belongs in your codebase
Paste raw JSON into a .js file and the linter lights up: quoted keys, double quotes everywhere, no trailing commas. This converter produces the idiomatic literal instead — identifier keys unquoted, your preferred quote style, optional trailing commas, and a declaration prefix — so static data drops into source cleanly.
Worked example
{ "app-name": "Reader", "version": 2, "default": true }becomes:
const data = {
'app-name': 'Reader',
version: 2,
'default': true
};Note the selective quoting: version is a valid identifier, while app-name (dash) and default (reserved word) must stay quoted — exactly the rule JavaScript itself applies.
When to use it
- Embedding fixtures, defaults and lookup tables in source files.
- Seeding Storybook stories and unit tests with realistic data.
- Converting captured payloads into mock modules.
Limitations to know
- The literal is static data — for runtime payloads keep JSON.parse.
- Long numbers beyond 15 digits lose precision in any JS literal; the tool warns and the fix is a string.
Related workflow
- Generate matching types with the JSON to TypeScript Converter — same sample in, interfaces out.
How to use the JSON to JavaScript Object Converter
- Paste JSON into the input panel.
- Choose quote style, trailing commas and the declaration prefix.
- Click "Convert to JavaScript".
- Paste the literal straight into your source file.
Frequently asked questions
What actually changes between JSON and a JS object literal?
Keys that are valid identifiers lose their quotes, strings switch to your preferred quote style, and you can add trailing commas and a declaration — the differences that make pasted JSON look foreign in a codebase. Values are untouched.
Why are some keys still quoted?
Because they must be: reserved words (default, class), keys with dashes or spaces, and keys starting with digits are not valid identifiers. The converter quotes exactly those and no more.
Is the output valid TypeScript too?
Yes — an object literal is the same in TS. If you want proper types alongside it, the JSON to TypeScript converter generates the interfaces to match.
Why trailing commas?
Cleaner git diffs: adding an item changes one line instead of two. Modern JS engines and formatters (Prettier, ESLint) fully support them — it is a style choice, hence the checkbox.