JSON to JavaScript
This converter turns JSON into a JavaScript object literal you can paste straight into your code. The wrapper can be const, export const, module.exports or a bare literal, and the variable name is configurable. Quote style, trailing commas, indentation and key sorting can all be set to match your codebase, and the conversion runs entirely in your browser — nothing is uploaded.
How to use it
- 1
Paste JSON
Drop the data into the editor, or pick a local file. It is read on your machine only.
- 2
Choose a wrapper
Pick const data = {…}, export const, module.exports = or a bare literal.
- 3
Set the variable name and quotes
Choose a variable name (data by default), single or double quotes, and whether to keep a trailing comma.
- 4
Copy into your code
Paste the result straight into a .js or .ts file.
Key features
Multiple wrappers
Generate const, export const, module.exports or a bare literal to fit different module styles.
Configurable variable name
Defaults to data and accepts any valid identifier.
Quotes and indentation
Single or double quotes, optional trailing commas and an indentation style you choose.
Value types preserved
Numbers stay numbers, booleans stay booleans and null stays null, because the literal holds real JavaScript values.
Paste-ready output
The result is valid JavaScript that evaluates to the same value as your JSON.
Local and private
The conversion runs in a Web Worker in your browser; nothing is uploaded.
Common errors & troubleshooting
- ! Bare-literal mode emits no variable declaration, which is handy when you inline the object as a function argument or on the right side of an assignment.
- ! A JavaScript object literal may keep a trailing comma, but switch it off if you plan to serialise the value to JSON for transport.
- ! The output preserves value types: numbers stay numbers, booleans stay booleans and null stays null.
- ! Nested objects and arrays are emitted as nested literals, so the structure is preserved exactly, ready to paste into your file.
Frequently asked questions
Can the generated code run as-is?
Yes. The output is a valid JavaScript object literal; paste it into a file using the wrapper you selected.
How is this different from JSON to JSON5?
JSON5 is still a data configuration format and needs a JSON5 parser; a JavaScript object literal is code that a JavaScript runtime can evaluate directly.
Can I change the variable name?
Yes. The name defaults to data and can be set to any valid identifier.
Is my data uploaded?
No. The conversion runs locally in your browser; nothing leaves your device.
Related tools
JSON to JSON5
Convert standard JSON to relaxed JSON5 with single quotes, unquoted keys and trailing commas. Quote style and indentation are configurable.
JSON to TypeScript
Generate TypeScript interface or type definitions from a sample JSON payload.
JSON Formatter
Format, beautify and validate JSON in your browser. Errors point to the exact line and column, and you can indent with 2 spaces, 4 spaces or a tab.