Developer Tools

JavaScript JSON Stringify Tool

Paste a JavaScript object or array exactly as it appears in source code, with unquoted keys, single quotes, comments, hexadecimal numbers and trailing commas, and get the JSON that JSON.stringify would produce. The literal is read by a real JavaScript parser but never executed, so function calls and variables are rejected rather than run. Choose the indentation, keep only certain keys, sort keys, or stringify twice to embed JSON in a string.

  • Runs in your browser
  • No sign-up
  • Free to use

How to use JavaScript JSON Stringify Tool

  1. Paste a JavaScript object literal, an array or JSON.
  2. Choose the indentation and output form.
  3. Optionally list keys to keep, or sort keys.
  4. Copy or download the JSON.

JavaScript JSON Stringify Tool features

Real JavaScript syntax

Unquoted keys, single and backtick quotes, comments, trailing commas, hex and leading-dot numbers.

Never runs code

Literals only: calls, variables and spreads are reported, not executed.

JSON.stringify options

Indentation, tabs and an array replacer that keeps chosen keys.

Double stringify

Produces a JSON string inside a string for embedding.

Honest conversions

Explains what happens to undefined, NaN, Infinity and BigInt.

Local

Runs in your browser; nothing is uploaded.

When to use JavaScript JSON Stringify Tool

  • Turning a config object from a JavaScript file into a JSON file.
  • Preparing a request body for an API client from code you already have.
  • Producing an escaped JSON string for a database column or environment variable.
  • Learning how JSON.stringify treats undefined and special numbers.

JavaScript JSON Stringify Tool FAQ

What does JSON.stringify do?

It converts a JavaScript value into JSON text. Keys get double quotes, strings are escaped, and values that JSON cannot represent are dropped or replaced.

What happens to undefined and functions?

JSON.stringify leaves out object properties whose value is undefined or a function, and turns them into null inside arrays. Because this tool never runs code, functions are reported as errors; undefined becomes null and is noted.

Why do NaN and Infinity become null?

JSON has no way to write them. JSON.stringify outputs null instead, and the tool tells you when that happened.

What is the “only these keys” box?

It is the array form of JSON.stringify’s replacer argument: only properties with those names are kept, at every level of nesting.

Why stringify twice?

Stringifying JSON text again produces a quoted, escaped string such as "{\"a\":1}", which is what you need when JSON must be stored inside another JSON value or a JavaScript string.

Is it safe to paste code?

Yes. The input is parsed into a syntax tree and only literal values are converted. Nothing is evaluated, and nothing leaves your browser.

From JavaScript literal to JSON

JavaScript object literals and JSON look alike, but JSON is much stricter. Keys must be double-quoted strings, strings must use double quotes, comments and trailing commas are not allowed, and numbers cannot be written in hexadecimal or with a leading dot. Code copied from a JavaScript file therefore rarely parses as JSON, even when it only contains data.

The usual shortcut, pasting the object into the browser console and calling JSON.stringify, runs whatever the code contains. This tool takes a safer route: the text is parsed with acorn, a standards-compliant JavaScript parser, and only literal nodes such as objects, arrays, strings, numbers and booleans are converted. Anything that would require execution, such as a function call, a variable reference or a spread, stops the conversion with the exact line and column.

JSON.stringify has two optional arguments that this page exposes. The replacer can be an array of property names; only those properties are kept, which is a quick way to strip internal fields before sharing data. The space argument controls indentation: a number of spaces up to ten, or a tab. Without it, the result is a compact single line, which is what APIs usually expect.

Some JavaScript values have no JSON equivalent. undefined disappears from objects and becomes null in arrays, NaN and Infinity become null, and BigInt values throw an error in real JSON.stringify. The tool converts what it can and lists every such change, so the JSON you copy does not silently differ from the data you meant.

Stringifying twice is a common need when JSON has to travel inside another string, for example in a database column, a message queue payload or an environment variable. The second pass escapes the quotes and backslashes of the first, producing a single string literal that JSON.parse turns back into the original text.

Other useful tools