JSON to JavaScript Object Converter
Turns JSON into a readable JavaScript object literal you can paste into source.
Loading the tool…
How to use this tool
- Paste the JSON, or load a .json file with the picker.
- Choose whether to wrap it in const, let, var, or nothing at all, and name the variable.
- Pick the quote style your project uses.
- Select Convert to an object literal, then copy the result straight into your source file.
What json to javascript object does
Pasting a JSON blob straight into a source file works, but it does not read like the code around it: every key is quoted whether it needs to be or not, and the quote style fights whatever the project uses. Reformatting it by hand is tedious and, on a large fixture, error-prone — the keys that genuinely must stay quoted are exactly the ones easiest to get wrong.
This page unquotes every key that is a valid JavaScript identifier and leaves quoted the ones that are not — anything with a dash or a space, anything starting with a digit, and reserved words like `class` and `default`. Strings are re-quoted in the style you choose, with the quote character properly escaped inside. You can wrap the result in a const, let or var declaration with a name of your choosing, or take the bare literal. Nothing is executed here: the input is parsed as JSON and rendered as text.