Web Tools
JavaScript Object to JSON
Convert JavaScript object literals to valid JSON. Handles single quotes, trailing commas, unquoted keys, comments, undefined, NaN, template literals, and hex/octal/binary numbers. Runs entirely in your browser.
json javascript converter parser formatter
Published May 29, 2026
All interactive tools run entirely in your browser. Your data never leaves your device.
How It Works
Paste a JavaScript object literal and instantly get valid JSON output. The tool parses relaxed JS syntax that JSON.parse() would reject — single quotes, trailing commas, unquoted keys, comments, and more — and converts it to strict JSON.
Features
- Single quotes:
'hello'becomes"hello" - Unquoted keys:
{ name: "val" }becomes{ "name": "val" } - Trailing commas: safely stripped from objects and arrays
- Comments:
//single-line and/* */multi-line comments removed - undefined/NaN/Infinity: converted to
nullwith warnings - Template literals: backtick strings converted to regular strings
- Hex/Octal/Binary:
0xFF,0o77,0b1010converted to decimal - Nested structures: handles deeply nested objects and arrays
- Warnings: shows what was converted (undefined, NaN, template literals)
- 5 examples: single quotes, trailing commas, unquoted keys, comments, mixed
- Private: runs entirely in the browser — no data transmitted
Use Cases
- Fixing “Unexpected token” errors when pasting JS objects into JSON fields
- Converting config objects from JS files to JSON format
- Cleaning up console.log output to valid JSON
- Converting JavaScript test fixtures to JSON data files
- Quick formatting of hand-written JS-style data structures