JavaScript

JavaScript Object to JSON Converter

Converts a JavaScript object literal into valid, formatted JSON.

Loading the tool…

Processing happens locally in your browser. What you paste or load is processed by this page and is not uploaded to a server. Nothing is stored unless you use a control that says it stores something, and you can clear anything this site has kept from the privacy page.

How to use this tool

  1. Paste the object or array literal — trailing commas, single quotes and comments are all fine.
  2. Set the indent, or use 0 to get the JSON on a single line.
  3. Select Convert to JSON.
  4. Check the note above the result if your input contained functions or undefined values — JSON cannot carry those.

What javascript object to json does

A JavaScript object literal and a JSON document look similar enough that people paste one where the other is expected and then spend ten minutes on the parse error. JSON requires double-quoted keys, double-quoted strings, no trailing commas, no comments and no expressions. An object literal allows all of those. Hand-fixing the difference on a large object is exactly the kind of edit that introduces a typo.

This page evaluates the literal in the same isolated worker the sandbox uses — no network, no access to this page — and then serialises the value as JSON. That means trailing commas, single quotes, unquoted keys, comments and computed values like `1000 * 60` are all handled, because the language handles them. It also means the conversion is honest about its limits: JSON has no representation for a function, for undefined, or for a symbol, so if the input contains any of those the result says which were dropped rather than quietly losing them.

Frequently asked questions

Because rewriting the text means reimplementing the language badly. Evaluating it means trailing commas, single quotes, comments, computed values like 1000 * 60 and nested literals all work exactly as they do in a real file. The evaluation happens in the same isolated worker the sandbox uses: no network, and no access to this page.

No — that is what JSON.stringify does, and it is the correct behaviour. JSON has no representation for a function, for undefined, or for a symbol. The result tells you which of those it noticed in your input so the loss is visible rather than silent.

This page expects a value — an object or array literal — not a fragment or a statement. Paste the literal itself rather than the assignment around it, and make sure it does not reference names that exist only in your project. If you meant to convert the other way, use the JSON to JavaScript object page.