Skip to main content

JSON Formatter & Validator

Format, validate and beautify JSON data with syntax highlighting.

Indent:
File name:
Ready

About this tool

The online JSON formatter quickly turns raw JSON into clean, readable text — perfect for debugging, documentation, and data analysis.

<p>The tool traverses the entire JSON object from the root and intelligently finds the first array of objects to also export as CSV. If the first object-array isn't the one you want, just paste a restructured array of objects and re-run.</p>

  • 3 indent options: 2 spaces, 4 spaces, or Tab
  • Optional alphabetical key sorting
  • One-click minify (compress to a single line)
  • Escape, unescape, and validate modes
  • 100% browser-side — your data never leaves your device

<p>Great for debugging API responses, cleaning up minified payloads, and preparing docs.</p>

Common use cases

  • Reading API responses. Paste a minified response body copied from a network trace or curl output and expand it into an indented, line-by-line view so nested objects and arrays are easy to scan.
  • Debugging rejected payloads. When a server answers with a generic 400 Bad Request, validating the body here surfaces the exact parser error reported by the browser engine instead of guessing.
  • Shrinking config and fixture files. Compress pretty-printed JSON into a single line before embedding it in environment variables, test fixtures, or source code.
  • Normalizing for diffs. Sorting object keys alphabetically makes two semantically identical documents textually comparable, which is handy when diffing exports from different systems.
  • Cleaning hand-edited files. Reformatting after manual edits restores consistent indentation and catches stray trailing commas or single quotes that the specification forbids.

How to use

  1. Paste or type your JSON into the left editor. Formatting runs automatically as you type, so no button press is required.
  2. Pick an indentation style from the Indent selector: 2 spaces, 4 spaces, or a tab character.
  3. Optionally enable Sort keys to reorder every object's keys alphabetically, recursively through nested objects.
  4. Read the formatted result in the right panel and use the copy button in its corner to put it on your clipboard.
  5. To minify instead, switch to the Compress tab, or click the primary action button, which applies the same single-line compression.
  6. Check the status bar below the editors: it reports validity, the line count, and the UTF-8 byte size of the output. Invalid input triggers a red banner with the underlying parser error.
  7. Use Sample to load example data and Clear to empty the editor.

Tips and pitfalls

Strict JSON (RFC 8259) allows no comments, no trailing commas, no single-quoted strings, and no unquoted keys. JSON5 and JSONC relax these rules, but this validator targets the strict grammar, because that is what every conforming parser accepts. When validation fails, the error message comes straight from your browser's JSON.parse implementation; modern engines include the character position, which usually points at or just after the real mistake.

Keep in mind that formatting is a parse-and-reserialize round trip, not a text pretty-printer. Number spellings are normalized (1.0 becomes 1, 1e3 becomes 1000), duplicate object keys collapse to their last value, and extremely large integers may lose precision because they pass through the IEEE 754 double type. If you must preserve such values byte-for-byte, edit the text manually instead.

Minifying removes whitespace, which helps, but for HTTP transport gzip or Brotli compression saves far more than whitespace stripping alone. Treat Compress as a convenience for storage and embedding, not as a substitute for transfer compression.

FAQ

Is my JSON uploaded to a server when I format it here?

No. All parsing and formatting happens locally in your browser using the built-in JSON.parse and JSON.stringify functions. No network request is made, so pasting sensitive API responses or configuration files is safe.

What is the difference between Format and Compress?

Format expands the document with line breaks and your chosen indentation (2 spaces, 4 spaces, or tabs) so it is easy to read. Compress does the opposite: it strips all insignificant whitespace and emits the smallest valid single-line representation of the same data.

Why does my input fail with a syntax error even though it looks fine?

The most common causes are trailing commas after the last array or object item, single-quoted strings, unquoted keys, or comments. Strict JSON (RFC 8259) forbids all of these. The red error banner shows the exact parser message from your browser engine, which in modern browsers includes the position of the offending character.

What does the Sort keys option do?

It reorders the keys of every object alphabetically, recursively through nested objects, while leaving array order untouched. Two documents with the same data but different key order produce identical output, which is useful for diffing.

Does formatting change my data?

The structure and values are preserved, but because the document is parsed and re-serialized, insignificant details such as whitespace, key order (when sorting is enabled), and number formatting (for example 1.0 becoming 1) are normalized. Duplicate keys collapse to the last occurrence, exactly as JSON.parse behaves.

What does the byte size in the status bar measure?

It is the UTF-8 encoded size of the formatted output, computed with a Blob. Multi-byte characters such as emoji or CJK text count as more than one byte, matching what would actually be sent over the wire or stored on disk.