JSON to JS Object
Convert JSON strings into native JavaScript Object format
Paste JSON, get a declaration ready for your source file
API responses and config files arrive as JSON, but when you want that data inside a script as a constant, quoted keys everywhere make it noisy. This tool parses your JSON, strips the quotes from property names, and wraps the result in a variable declaration so you can drop it directly into a JavaScript file.
Steps
- Paste your JSON into Source JSON, or press Load Sample to see a user and permissions example.
- Type a name in Variable Name. It defaults to data, and blank falls back to data as well.
- Pick a Variable Type: const, let, var, or None (Object only) for the bare literal.
- Click Convert to JS Object and copy the text from the JS Object Format panel.
If the input is not valid JSON, an alert says Invalid JSON and includes the parser's message so you can locate the problem.
What the output looks like
The JSON is parsed, re-indented with four spaces, keys are unquoted, and the result is run through a JavaScript beautifier. Strings keep their double quotes. A declaration such as const data = { user: "admin", active: true }; is the typical result, laid out over several lines.
Where it is useful
- Embedding an API sample response as a fixture in a unit test.
- Pasting settings from a JSON file into an inline script or a configuration module.
- Building mock data for a front-end prototype without a backend.
- Rewriting a JSON snippet in documentation to match the style of your codebase.
Limits to watch for
Unquoting is done with a pattern replacement, and it applies to every key. That is fine for plain names, but a key that is not a valid identifier, such as one containing a hyphen or space, or starting with a digit, will come out unquoted and break the resulting code. If your keys look like first-name or 2024, quote them again by hand. A pattern like that can also affect text inside a string value that resembles a key followed by a colon. Review the result before committing it. The conversion runs in your browser and does not need a server round trip.
Related Tools