Skip to content
gohacks.dev
Standard Library

JavaScript Object to JSON Converter

Convert a JavaScript object literal or JSON5 to strict JSON: unquoted keys, single quotes, comments and trailing commas are all handled.

Free · No sign-up · Your inputs stay in your browser

Input

Convert a JavaScript object or JSON5 to JSON

Output

JSON

176 characters

Reads what JSON.parse refuses: comments, unquoted keys, single quotes, trailing commas, hex numbers and a leading export default or const x =. undefined, NaN and Infinity have no JSON form, so they become null. Template literals are read as plain strings; ${} is not evaluated.

Runs in this browser. Nothing you paste is sent to a server.

Why JSON.parse rejects it

JSON is deliberately smaller than JavaScript: keys must be double-quoted, there are no comments and no trailing commas (RFC 8259). Config copied out of a .js file, a browser console or a JSON5 file such as tsconfig.json usually breaks one of those rules, which is why pasting it into an API client fails.

Nothing is evaluated

The input is parsed, never run with eval, so pasting untrusted code here is safe. That also means expressions are not computed: a value like 60 * 60 or process.env.PORT is reported as an error rather than guessed.

Share

Frequently asked questions

Is JSON5 the same as a JavaScript object?
Close. JSON5 adds comments, unquoted keys, single quotes, trailing commas, hex numbers and Infinity to JSON, which covers most object literals people paste. Functions, variables and computed keys are JavaScript only.
Why does tsconfig.json allow comments?
TypeScript reads it with its own lenient parser (often described as JSONC, JSON with comments). Other tools that read tsconfig.json with a strict parser fail on the same file.
Is what I paste sent anywhere?
No. The tool runs entirely in your browser with JavaScript. Nothing you type or paste is sent to our server or stored.

Keep planning

Similar tools