Skip to content
Browser tool Runs locally

JavaScript Object ⇄ JSON

Convert a JavaScript object literal to JSON, or JSON back to a JavaScript object. Runs locally in your browser.

JavaScript Object
JSON
Converted output will appear here.

How it works

The tool parses JavaScript source using the same ECMAScript parser the JavaScript Formatter uses. Only literal structures are converted - no code is executed, and no identifiers are resolved.

What JavaScript → JSON accepts

  • A single object literal, array literal, or primitive literal.
  • Optionally wrapped in parentheses.
  • Optionally assigned to a single const/let/var.
  • Comments, single quotes, and trailing commas are all fine.

What it rejects

  • Identifiers, expressions, or function calls.
  • Object methods, spread, computed keys, or accessors.
  • BigInt and regular expressions.

JSON → JavaScript output

Produces a JavaScript object literal with unquoted safe identifiers and 2-space indentation. Keys that are not valid JavaScript identifiers remain quoted.

JavaScript object notation is broader than JSON

JavaScript object literals can use features such as comments, single-quoted strings, trailing commas, methods, shorthand properties, computed keys, and expressions. JSON is stricter: keys and string values use double quotes, and values must be representable as JSON data. This converter accepts only the literal structures it can convert without executing code.

Frequently asked questions

Does this run my JavaScript?
No. The parser reads the source as text and extracts a literal-only structure. Nothing is evaluated.
What input does JavaScript → JSON accept?
A single object literal, array literal, or primitive literal, with optional surrounding parentheses or a single const/let/var declaration.
Are comments, single quotes, and trailing commas OK?
Yes. They are stripped during parsing; comments are not evaluated.
What about functions, spread, or computed keys?
Those cannot be represented in JSON and are reported as errors instead of being silently dropped.
What does JSON → JavaScript produce?
A JavaScript object literal with unquoted safe identifiers, escaped string values, and 2-space indentation.

Related tools