Skip to main content

JSON Formatter

Pretty-print, validate, and minify JSON with a clear error line and column.

Written by Golam Rabbani, Founder & Lead Engineer

How to use this json formatter

  1. Paste or type your JSON into the JSON Input textarea.
  2. Choose an indent size — 2 spaces, 4 spaces, or Tab — from the Indent select, or switch Mode to Minify.
  3. Click Format to process the input.
  4. If the input is invalid, read the error message; the line and column numbers point to the exact problem character.
  5. Click Copy to copy the formatted output, or Reset to clear everything and start over.

About this json formatter

The JSON formatter takes raw JSON text and returns it either pretty-printed with consistent indentation or stripped down to a single-line minified string. Developers reach for it when debugging API responses that arrive as a wall of text, comparing two payloads side by side, or trimming whitespace before sending data over the wire.

The tool works by parsing the input with the browser's built-in JSON.parse, which validates structure at the same time. If parsing succeeds, JSON.stringify re-serialises the result using your chosen indent setting (2 spaces, 4 spaces, or a literal tab character). For minify mode, JSON.stringify is called without an indent argument, collapsing all whitespace. When parsing fails, the native SyntaxError message is examined for a character-position offset; the formatter converts that offset into a line number and column number by splitting the input on newline characters, so you see "Line 3, Column 12" rather than a cryptic byte index.

For example, pasting {"id":1,"name":"Ada","tags":["math","cs"]} and selecting Pretty print at 2-space indent produces a six-line block with each key on its own line and the array items indented under "tags". The output byte count is shown so you can compare the original and formatted sizes at a glance.

The json formatter runs entirely in your browser — your JSON is never transmitted to a server or stored anywhere.

FAQ

What does a json formatter actually do?
It parses your JSON text to verify it is valid, then re-serialises it with your chosen indentation (pretty print) or strips all whitespace (minify). The result is structurally identical to the input — only the whitespace changes.
Why would I minify JSON?
Minified JSON is smaller in bytes, which reduces payload size when sending data over HTTP. Removing whitespace from a large API response or config file can cut its size by 20–40 percent, which matters in high-volume or bandwidth-constrained environments.
How are the line and column numbers in error messages computed?
When JSON.parse throws a SyntaxError, the tool extracts the character-position offset from the error message. It then slices the input up to that offset and counts newline characters to get the line number; the column is the length of the last line fragment plus one.
Does this tool send my JSON to a server?
No. Parsing and formatting happen entirely in your browser using the native JSON.parse and JSON.stringify APIs. Nothing is transmitted, logged, or stored — closing the tab discards the data immediately.
What indent options are available?
The Indent select offers three options: 2 spaces, 4 spaces, and Tab. The choice only affects pretty-print mode; minify mode ignores the indent setting and always removes all whitespace.
Are trailing commas or comments supported?
No. The formatter uses strict JSON parsing, which does not allow trailing commas, JavaScript-style comments, or single-quoted strings. If your input contains any of these, the tool will report a syntax error with the line and column of the offending character.