Free · Fast · Privacy-first

JSON Formatter JavaScript, Beyond JSON.stringify

JavaScript developers know JSON.stringify(obj, null, 2) as the standard way to pretty print an object, but when you already have a raw JSON string and just want to read it clearly, there is no need to open a console.

Browser equivalent of JSON.stringify(obj, null, 2)

🔒

Syntax highlighted output with correct types

Works for non-developers who cannot run JS

No console, no Node.js, no code needed

Cost
Free forever
Sign-up
Not required
Processing
In your browser
Privacy
Files stay local
FreeNo signupWhite-label

Add this JSON Formatter to your website

Drop the JSON Formatter into any page — blog post, product docs, intranet, school portal — with a single line of HTML. Your visitors get the full tool, processed entirely in their browser. No backend, no uploads, no signup.

  • Files stay 100% in the visitor's browser
  • Responsive — adapts to any container width
  • Free forever, no API key needed

Embed code

<iframe
  src="https://www.fixtools.io/json/json-formatter?embed=1"
  width="100%"
  height="780"
  frameborder="0"
  style="border:0;border-radius:16px;max-width:900px;"
  title="JSON Formatter by FixTools"
  loading="lazy"
  allow="clipboard-write"
></iframe>

Attribution-friendly: a small "Powered by FixTools" link appears in the embed footer.

JSON.stringify as a Formatter, and Its Limitations

JSON.stringify() is JavaScript's built-in JSON serializer, defined in the ECMA-262 specification since ES5 in 2009. When called with a space argument, it produces human-readable indented output. JSON.stringify(obj, null, 2) produces 2-space indented JSON. JSON.stringify(obj, null, "\t") produces tab-indented JSON. The second argument is a replacer: null includes all enumerable own properties, an array of strings includes only those named properties, and a function is called for each key-value pair and can transform or exclude individual values. This flexibility makes JSON.stringify suitable for both full serialization and filtered output.

The core limitation of JSON.stringify as a formatting tool is that it requires a JavaScript data structure as input, not a JSON string. If you already have a serialized JSON string from an API response, a log file, or a config file, you need JSON.parse() first: JSON.stringify(JSON.parse(jsonString), null, 2). This two-step sequence requires either a browser console, a Node.js REPL, or a dedicated script. For developers who use the console daily this is fast. For non-developers, for people on restricted machines, or for anyone who simply wants a faster path, this is unnecessary friction.

FixTools wraps this two-step operation in a web interface accessible from any browser. The input accepts a raw JSON string. Under the hood, the tool calls JSON.parse() to validate and deserialize the input, then JSON.stringify() with the chosen indent to produce the formatted output. The browser engine provides syntax highlighting on the rendered result, distinguishing strings, numbers, booleans, null, keys, and structural characters by colour. The final output is equivalent to what you would get running the same commands in the browser console, with better readability and a one-click copy button.

JavaScript has several JSON quirks that catch developers off-guard. BigInt values are not serialisable by JSON.stringify and throw a TypeError, even though they parse cleanly with JSON.parse if presented as plain integers; use a toJSON method on a wrapper class or stringify them to plain strings first. Object key order rules in V8 list integer-like keys numerically first regardless of insertion order, then string keys in insertion order, then Symbol keys (which JSON skips entirely). The U+2028 line separator and U+2029 paragraph separator are valid in JSON strings under modern specs but break older JavaScript parsers that use eval-based JSON handling, so libraries like jsesc escape them defensively. Knowing these quirks turns mysterious cross-runtime drift into a one-line fix at the serialisation boundary.

JSON.stringify also intersects with JavaScript module boundaries in ways that bite during debugging. When logging an object that was loaded from a different realm or worker, properties may not appear because property descriptors mark them non-enumerable; JSON.stringify only walks enumerable own properties. Class instances with private fields lose the private state entirely because private fields are not enumerable own properties of the instance. Proxy objects appear normal but JSON.stringify invokes their ownKeys and getOwnPropertyDescriptor traps, which may return different data than direct property access. For thorough debugging of complex objects, combine JSON.stringify with Object.getOwnPropertyNames or Reflect.ownKeys to enumerate every property name, including non-enumerable ones, and inspect each value explicitly before deciding whether the omission from stringified output is correct or a missing case.

TypeScript adds another layer worth understanding. The TypeScript compiler types JSON.parse as returning any, which defeats type safety unless you assert the result. The common pattern const data = JSON.parse(text) as MyType is unsafe because TypeScript performs no runtime check that the parsed value actually matches the type. Libraries like zod, io-ts, and superstruct add schema validation at the parse boundary, producing a typed value or a clear validation error. For greenfield TypeScript projects, adopt one of these libraries at every API and storage boundary; the small runtime cost prevents an entire category of bugs where TypeScript believes a value is one shape but the runtime value is another. FixTools complements this approach by giving you a quick way to inspect the actual JSON shape before defining the schema.

How to use this tool

💡

Paste any JSON string for instant browser-based formatting. Equivalent to running JSON.stringify(JSON.parse(raw), null, 2) in a JavaScript console.

How It Works

Step-by-step guide to json formatter javascript, beyond json.stringify:

  1. 1

    Get your JSON string

    Copy the raw JSON string from your API response, log output, build artifact, or config file. If you have a JavaScript object rather than a string, first run JSON.stringify(obj) in your browser console to convert it to a raw JSON string, then copy the resulting string to your clipboard for pasting into FixTools.

  2. 2

    Paste into FixTools

    Open fixtools.io/json/json-formatter in any browser and paste the raw JSON string into the formatter input area. The input accepts raw JSON text of any length and structure. No preprocessing or escaping is required.

  3. 3

    Click Format

    Click the Format button. FixTools internally calls JSON.parse() on your input to validate and parse it, then JSON.stringify() with 2-space indentation to produce the formatted output. This is identical to running JSON.stringify(JSON.parse(rawString), null, 2) in a browser console, but with syntax highlighting and a copy button added on top.

  4. 4

    Copy the output

    Click the Copy button to copy the fully formatted JSON string to your clipboard. Paste it into your code editor, a PR comment, API documentation, or a test fixture file. The output is standards-compliant JSON that any JavaScript parser will accept without modification.

Real-world examples

Common situations where this approach makes a real difference:

Non-developer project manager

FixTools extends JSON formatting access to people who do not write JavaScript.

JavaScript developer

Formatting JSON from PR comments or documentation saves review time for the whole team.

React developer

Design-to-code handoffs often involve JSON structures that need formatting to plan the component model.

Test author

Test fixtures for JavaScript API clients should always be reviewed as formatted JSON before committing.

Pro tips

Get better results with these expert suggestions:

1

JSON.stringify(obj, null, 2) is the canonical JavaScript format command

The pattern JSON.stringify(obj, null, 2) appears in thousands of JavaScript tutorials and debugging guides. Memorize the three arguments: the value to serialize, the replacer (null means include all enumerable own properties), and the indent width (2 produces 2-space indentation). For a tab-indented result, pass "\t" as the third argument instead of 2. This pattern works identically in browser consoles, Node.js, Deno, and Bun.

2

Use console.dir for non-JSON-serializable objects

Some JavaScript objects contain functions, Symbols, or circular references that JSON.stringify cannot handle and will throw a TypeError for. console.dir(obj) in Chrome DevTools displays the full object tree interactively without needing to serialize it to JSON. For class instances that mix data properties with methods, console.dir is more reliable than JSON.stringify for inspection because it shows all properties including non-serializable ones.

3

The replacer array filters keys

JSON.stringify(obj, ["name", "age"], 2) produces JSON that includes only the "name" and "age" keys, even if the object has many more properties. The array replacer applies recursively to all nested objects at every depth. This is useful for logging a focused subset of a large object or for producing a sanitized version of a data structure that omits sensitive fields like passwords or tokens.

4

toJSON() method controls serialization

If a JavaScript object defines a toJSON() method, JSON.stringify() calls it and serializes the return value rather than the object's own properties. This is how Date objects are automatically serialized to ISO 8601 strings. Custom classes can implement toJSON() to control their JSON representation, producing cleaner output than a raw property dump. This is useful for value objects like Money, Duration, or GeoPoint that have a canonical JSON form.

FAQ

Frequently asked questions

JSON.stringify() is the built-in JavaScript function for serializing values to JSON strings. The three arguments are: the value to serialize, a replacer (null means include all enumerable own properties), and a space argument (2 means use 2-space indentation per nesting level). The result is a formatted JSON string. To format a raw JSON string you already have, use JSON.stringify(JSON.parse(rawString), null, 2), which parses first and then re-serializes with indentation.
Use JSON.stringify(JSON.parse(rawString), null, 2). JSON.parse() converts the raw JSON string to a JavaScript value. JSON.stringify() converts it back to a JSON string with 2-space indentation. No external library or npm package is required. This works in any modern browser console, Node.js, Deno, and Bun. For a visual result with syntax highlighting and a copy button, paste the raw string into FixTools instead of writing the code.
The replacer is the second argument to JSON.stringify(). Passing null includes all enumerable own properties in the output. Passing an array of strings includes only the keys named in the array, applied recursively at every nesting level. Passing a function calls it for each key-value pair and uses the return value in the output, allowing transformation or exclusion of individual properties. For standard formatting that includes all data, pass null.
No. JSON.stringify() throws a TypeError if the object contains a circular reference (a property that points back to an ancestor object). JSON does not support circular structures because it is a linear text format. To serialize objects with cycles, use the flatted or circular-json npm package, which represents cycles using a custom notation. Alternatively, remove the circular reference before calling JSON.stringify(). The console.dir() function can display circular objects in DevTools without serializing them.
FixTools uses JSON.stringify() under the hood. When you click Format, the tool calls JSON.parse(input) to validate and parse the string, then JSON.stringify(parsed, null, indentSize) to produce the formatted output. The result is identical to what you would get by running the same two-step command in the browser console. FixTools adds syntax highlighting, which colours different token types, and a copy button on top of this core operation.
Use console.log(JSON.stringify(obj, null, 2)) to print a formatted JSON representation of any JavaScript object to stdout. For writing to a file, use fs.writeFileSync("output.json", JSON.stringify(obj, null, 2)). The util.inspect() function is an alternative that handles circular references and non-JSON types such as Sets and Maps, but it produces JavaScript syntax rather than valid JSON, which means other languages cannot parse the output.
JSON.stringify handles strings, numbers, booleans, null, arrays, and plain objects. It omits object properties whose values are undefined, functions, or Symbols. It converts Date objects to ISO 8601 strings using their toJSON() method. It throws a TypeError for BigInt values and for objects with circular references. Use the replacer function argument to convert unsupported types to a JSON-compatible form before serialization.
Yes. FixTools requires no technical knowledge to use. Paste any JSON string, click Format, and read the indented, colour-highlighted output. The syntax colouring distinguishes strings, numbers, booleans, and null values visually without requiring the reader to understand JSON syntax rules. Non-developers such as project managers, business analysts, and customer support staff can inspect JSON data shared by developers without needing to learn any programming tool.
The position number reports the byte offset where the parser saw an unexpected character. Open your input in any editor that shows character offsets (the VS Code status bar shows Ln/Col, which you can convert) or paste into FixTools to see the highlighted error. The four most common offenders are: a trailing comma at position N-1 right before a closing brace or bracket, an unquoted key starting at position N, a missing comma between two adjacent key-value pairs causing the parser to see an unexpected double-quote, and a smart-quote character (U+201C or U+201D) instead of a straight ASCII double-quote, which often happens when JSON is copy-pasted from a Slack message or a Word document that auto-corrected the quotes.
V8's JSON.stringify is implemented in C++ and is extremely fast for general-purpose use, but it spends cycles inspecting the type of every value. Schema-aware serialisers such as fast-json-stringify (used inside Fastify) precompile a serialiser function from a JSON Schema, skipping type checks and producing output 2 to 5 times faster on hot paths. For a high-throughput API serving thousands of JSON responses per second, this matters; for occasional formatting in a browser, it does not. FixTools uses JSON.stringify because formatting is not throughput-bound and because the schema-aware approach requires per-document schema definitions that are impractical for an interactive paste tool. For backend services, profile first and adopt fast-json-stringify only where the JSON.stringify call appears in a flame graph. Premature switching can mask correctness issues because schema-aware serialisers skip the type-check work and trust the schema to be accurate.

Ready to get started?

Open the full JSON Formatter — free, no account needed, works on any device.

Open JSON Formatter →

Free · No account needed · Works on any device