JavaScript to JSON Converter
Paste a permissive JavaScript object literal — with unquoted keys, single quotes, trailing commas, or comments — to instantly convert it into strict, valid JSON. Free online developer tool.
Paste JavaScript Object Literal
Strict JSON
Strict JSON will appear here...
Free JavaScript to JSON Converter
Paste a permissive JavaScript object literal — with unquoted keys, single quotes, trailing commas, or comments — to instantly convert it into strict, valid JSON. This is the reverse of simply reading JSON as JavaScript: it takes the relaxed syntax developers actually write in config files and source code and produces output that passes JSON.parse anywhere.
How to Use It
Paste any JS object literal into the input box, or click "Load Example" to see a sample with unquoted keys, single-quoted strings, an inline comment, and a trailing comma all handled at once. The tool parses the input using the JSON5 spec (a superset of JSON that permits this relaxed syntax) and then re-serializes it as pretty-printed, strict JSON.
Example
{ name: 'Ann', age: 30, /* a comment */ tags: ['a', 'b',], } becomes valid JSON with quoted keys, double-quoted strings, the comment stripped, and the trailing comma removed:{ "name": "Ann", "age": 30, "tags": ["a", "b"] }.
Common Use Cases
- Converting a hand-written JavaScript config object into a strict
.jsonconfig file. - Cleaning up a JS object copied from source code so it can be pasted into a JSON-only tool or API.
- Fixing trailing-comma or unquoted-key errors that break
JSON.parse. - Stripping comments out of a JSON5/JSONC file before feeding it to a strict JSON parser.
FAQs
What exactly counts as valid input?
Anything valid under the JSON5 specification — unquoted or single-quoted keys, single-quoted strings, trailing commas in objects and arrays, single-line and block comments, and a few extra numeric literals like leading + and hexadecimal numbers.
What happens with functions or undefined values?
JSON5 (and JSON itself) doesn't support function values, undefined, or other non-serializable JavaScript values — if your input contains any of these, parsing will fail with an error rather than silently dropping them.
Is my data uploaded anywhere?
No — parsing and conversion happen entirely client-side in your browser using the JSON5 library. Nothing you paste is sent to a server.
