JS to JSON Converter
Convert JavaScript Objects/Arrays into valid JSON strings
From JavaScript object literal to strict JSON
A JavaScript object such as { name: 'Dev', id: 101 } is not valid JSON: the key has no quotes and the string uses single quotes. Config files, APIs and most parsers want the strict form. This converter evaluates the literal you paste and outputs it as properly quoted, four-space-indented JSON.
Converting an object
- Paste a JS object or array into the JS Object/Array box. Load Sample fills in a small app description with a features list.
- Decide whether to keep Strip Functions (Keep Data Only) ticked. It is on by default.
- Click Convert to JSON.
- Copy the text from the JSON Result panel with the Copy button.
If the input cannot be evaluated, a browser alert says Invalid JS Object. Nothing is changed in the input, so you can fix the problem and try again.
What you can paste
- Object literals with unquoted keys, single-quoted or backtick strings, and trailing commas.
- Arrays of objects, nested structures, numbers, booleans and null.
- Expressions that produce a value, such as new Date() or 60 * 60, which are computed before conversion.
How JSON differs from JavaScript
JSON has no functions, no undefined and no comments. With stripping enabled, function properties are removed from the output. Properties whose value is undefined are dropped in every case, and inside arrays they become null. Dates become ISO strings, and values like NaN and Infinity become null. Numbers such as 1.0 print as 1.
Typical situations
- Turning a config object copied from source code into a .json file.
- Preparing sample data for an API request body or a mock server.
- Cleaning up a snippet from documentation that uses JavaScript-style keys.
- Converting data exported from a browser console into something a JSON tool accepts.
Safety note
To read your input, the tool actually evaluates it as JavaScript in your browser. That means any code inside the input will run, including function calls and network requests. Only paste literals you understand and trust, and never paste code from an unknown source. Conversion itself takes place on the page rather than through a server request. If the result looks wrong, check that every bracket and quote in the input is closed, because a single missing brace stops the evaluation and triggers the alert.
Related Tools