DevKit
Converter

JS Object to JSON

Convert JavaScript object literals to valid JSON.

Last updated: August 2026

Share:

Was this tool helpful?

Object literals are not JSON

A JavaScript object literal and a JSON document look similar but follow different rules. JS lets you write unquoted keys, single quotes, trailing commas, comments, and values like undefined. JSON allows none of that. This tool rewrites a JS object into strict JSON so it can be stored, sent over the wire, or fed to a parser that only accepts the standard.

Example

JS input:

{
  name: 'Ada',      // unquoted key, single quotes
  tags: ['x', 'y',], // trailing comma
}

Valid JSON output:

{
  "name": "Ada",
  "tags": ["x", "y"]
}

Keys get double-quoted, string quotes switch to double, the trailing comma is dropped, and the comment is removed.

Values with no JSON equivalent

Some JS values simply cannot be represented. undefined, functions, and symbols have no JSON form, mirroring how JSON.stringify drops them. NaN and Infinity are not valid JSON numbers either and usually become null or an error. If your object relies on those, the conversion is lossy by necessity.

A note on safety

Converting by actually executing the input with eval is dangerous, since a crafted literal can run arbitrary code. A sound converter parses the text rather than evaluating it, so paste from untrusted sources with that in mind.

FAQ

Why did my function property disappear? JSON has no function type, so methods are dropped, exactly as JSON.stringify would.

What about dates? A Date has no JSON literal; it typically serializes to an ISO string. Reconstructing it is on the consumer.

Can I go the other way? JSON is already valid JS, so round-tripping is one-way interesting; use a JSON formatter to tidy the result.