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
- Paste the JSON or open a .json file.
- Pick the declaration: const, export default, module.exports or just the object.
- Choose single or double quotes and the indentation.
- 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.