JavaScript

JSON to JavaScript Object Converter

Turns JSON into a readable JavaScript object literal you can paste into source.

Loading the tool…

Processing happens locally in your browser. What you paste or load is processed by this page and is not uploaded to a server. Nothing is stored unless you use a control that says it stores something, and you can clear anything this site has kept from the privacy page.

How to use this tool

  1. Paste the JSON, or load a .json file with the picker.
  2. Choose whether to wrap it in const, let, var, or nothing at all, and name the variable.
  3. Pick the quote style your project uses.
  4. 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.

Frequently asked questions

Any key that is not a valid JavaScript identifier: anything containing a dash, a space or a dot, anything starting with a digit, and reserved words such as class, default and new. Everything else loses its quotes. The summary counts both so you can see at a glance how many were kept.

No. This direction is pure text: the input is parsed with JSON.parse and rendered back out as an object literal. Nothing is compiled and no worker is involved.

Yes — set the declaration option to "No declaration". You will get the bare literal, which is what you want when you are pasting it as a function argument or into an existing object.