JS Object to JSON Converter
Convert a JavaScript object literal into valid JSON, handling unquoted keys, single quotes, trailing commas and comments.
Need this built for your product?
We design, build & host secure software & APIs.
Why a JS object is not JSON
JSON was derived from JavaScript object syntax but is far stricter. A JavaScript literal permits unquoted keys, single-quoted strings, trailing commas, comments, and values JSON has no representation for. Pasting one into a JSON parser fails immediately, which is the single most common JSON parse error in practice.
What has to change
Keys must be double-quoted. Strings must use double quotes, and any double quote inside them must be escaped. The trailing comma after the final element must go. Comments must be removed entirely, since JSON has no comment syntax at all. Each of these is mechanical, and doing them by hand on a large object is where mistakes creep in.
Values with no JSON equivalent
Some JavaScript values simply cannot be represented. undefined has no JSON form; a property holding it is dropped rather than converted. Functions and symbols likewise disappear. NaN and Infinity are valid JavaScript numbers and invalid JSON, so they must become null or a string. A Date object becomes an ISO string. Knowing which of these your object contains matters, because the conversion silently loses them rather than erroring.
Large numbers lose precision
JSON numbers are parsed as doubles, exact only to 2^53-1. A JavaScript BigInt cannot be serialised at all and throws. A 64-bit identifier held as a number silently rounds. Convert large identifiers to strings before they reach JSON, not after.
Single quotes inside strings
Converting single-quoted strings to double-quoted is not a straight character swap. A string delimited by single quotes may contain unescaped double quotes, which become syntax errors once the delimiters change. Those inner quotes need escaping as part of the conversion, and this is the step hand-editing usually misses.
JSON5 exists
If you want comments and trailing commas in a configuration file, JSON5 permits both and several tools accept it. It is not JSON, so anything expecting strict JSON will still reject it, but it is a reasonable middle ground for files humans edit.
Frequently Asked Questions
Privacy & Security
All processing happens locally in your browser — nothing is uploaded.
How to Use
Paste a JS object or loose JSON; valid formatted JSON is produced.
Disclaimer: This tool is provided "as is" without warranty of any kind. Results are for educational and utility purposes.
Related Tools
JSON Formatter
DeveloperFormat and beautify JSON in your browser. Pinpoints syntax errors by line and column, flags unsafe integers, and never uploads your data to a server.
JSON Validator
DeveloperValidate JSON syntax with precise line and column errors, and check documents against a JSON Schema. Runs locally in your browser, nothing uploaded.
Regex Tester
DeveloperTest regular expressions against sample text with live match highlighting, capture groups and flag control. Runs entirely in your browser.