ToolStudio.es
In your browser1 Free Trial

Convert JSON to JavaScript

Turn JSON into a JavaScript object literal ready to paste into your code, in the quote and declaration style you use.

Free try: process 1 document (pasted or 1 file) and change the options as often as you like. Errors do not use up your try.
Input · JSON

Everything runs in your browser: your data is never sent to a server.

Result · JavaScript
Declaration
Quotes
Indentation

From JSON to a JavaScript object

JSON looks like JavaScript but isn't the same: it requires double quotes around every key. When you paste data into your code, you usually want it in your project's style: unquoted keys, single quotes and a declaration such as const or export default.

This tool does that for you. It removes the quotes from keys that are valid JavaScript identifiers, writes strings with single or double quotes, adds the declaration you choose (const, export default or module.exports) and, if you like, trailing commas.

Numbers are copied as-is and special characters in strings are escaped correctly.

How to convert JSON to JavaScript

  1. Paste the JSON or open a .json file.
  2. Pick the declaration: const, export default, module.exports or just the object.
  3. Choose single or double quotes and the indentation.
  4. Click “Convert to JavaScript” and copy the code or download the .js file.

When to use it

  • Pasting sample data or mocks into a test.
  • Turning a JSON config file into a JavaScript module.
  • Creating constants with lists of countries, categories or translations.
  • Adapting JSON to your project's style (Prettier, ESLint).

Frequently Asked Questions

What's the difference between JSON and a JavaScript object?

JSON is a text format with strict rules: keys in double quotes, no comments and no trailing commas. A JavaScript object literal allows unquoted keys, single quotes, trailing commas and expressions.

Why are some keys still quoted?

Because they aren't valid JavaScript identifiers, for example “first-name” or “1st”. Those need quotes for the code to work.

Can I use the result in TypeScript?

Yes, it's valid JavaScript and valid TypeScript too. If you also want the types, use the JSON to TypeScript converter.

Is my data sent to a server?

No. Everything is processed in your browser with JavaScript. The text you paste and the files you open never leave your device, so you can safely work with internal or customer data.

Is it free?

Yes. You can try the tool for free on one document (pasted or a single file) and change the options as often as you like; attempts that end in an error don't use up your free try. For unlimited use and processing several files at once, ToolStudio Pro costs €1.99 a month and includes every tool.

Related tools

Development

JSON to TypeScript Converter

Create TypeScript interfaces or types from JSON: objects in a list are merged into one type, missing keys become optional (?) and unions are created when values differ.

JSONTypeScript
Try this tool
Development

JSON Formatter

Paste minified or messy JSON and get it back indented with 2 or 4 spaces or tabs, with sorted keys if you want. Any error is shown with its line and column.

JSON
Try this tool
Development

JSON Minifier

Compact JSON into a single line without changing any value and see how much smaller it gets. Handy for APIs, config files and lighter requests.

JSON
Try this tool
Development

JSON Validator

Validate JSON against the RFC 8259 standard with every error explained in plain words: trailing commas, single quotes, unquoted keys or comments. It also flags duplicate keys.

JSON
Try this tool
Featured on TinyShelf