JSON Formatter & Validator

Format, minify and validate JSON instantly — with precise error location.

{{ __t('indent_label') }}
{{ __t('bytes') }} {{ __t('lines') }} {{ __t('keys') }} {{ __t('saved') }}

What is JSON?

JSON (JavaScript Object Notation) is a lightweight, human-readable, easy-to-parse data format. It has become the standard data format on the web — used for REST APIs, config files, and NoSQL databases.

This tool helps tidy up hard-to-read JSON strings (e.g. from API responses), minify for production, and locate syntax errors with exact line and column information.

Features

  • Format — pretty-print with 2 / 4 spaces or tabs
  • Minify — strip all whitespace for the smallest size
  • Validate — syntax check with line/column on errors
  • 100% local — no upload, no server, no logs

JSON syntax in a nutshell

JSON is strictly specified (RFC 8259). Common gotchas that cause parser errors:

  • Strings must be wrapped in double quotes, not single
  • Object keys must also be in double quotes
  • No trailing commas allowed — no comma after the last element
  • Comments are not part of the JSON spec

JSON Formatting: Specification, Pretty-Print and Minify

JSON has been specified since December 2017 in RFC 8259 and in parallel in ECMA-404. The standard allows six value types — string, number, true/false, null, object, array — and mandates UTF-8 as the default encoding for data exchange between systems. Whitespace between tokens is irrelevant to machines but vital to humans: an API response like {"a":1,"b":[2,3,{"c":"d"}]} is hard to read, while the formatted version with two-space indentation makes structure, ownership and depth immediately visible.

Formatting (beautify) inserts line breaks and indentation without changing semantics. Common indentations are 2 or 4 spaces or tabs — most style guides (Airbnb, Google, Prettier default) prefer 2 spaces. Minify is the inverse: every non-significant whitespace is stripped, typically shrinking the file by 20–40%. This saves bandwidth on API responses and is mandatory for in-body payloads in Lambda Edge functions or Service Workers, where every byte matters.

Strictly per RFC 8259, comments are forbidden, single quotes are illegal and trailing commas are invalid. Browsers and Node.js (via JSON.parse) are unforgiving here. More tolerant variants include JSON5, HJSON or JSONC (the VSCode config flavor). Our formatter sticks to the standard; if you have JSONC or JSON5 input, run it through a matching parser first before validating here.

How to Use the JSON Formatter

Five steps from a raw blob to cleanly structured JSON:

  1. Paste your JSON into the left field — from curl output, an API response, a .json file or a DevTools console dump.
  2. Pick the indentation: 2 spaces for most style guides, 4 for PEP-8-style conventions, tab for classic C/Java codebases. The choice applies the moment you click Format.
  3. Click Format for pretty-print, Minify for the compact variant or Validate for syntax-only checking. On errors the offending line and column are reported.
  4. Read the stats below: bytes, lines, key count and on minify the percent saved. You instantly see what you gain in bandwidth or storage.
  5. Copy the output into your codebase, your Postman request or a .har file. Tip: the URL parameter ?data= automatically shares the input JSON — handy for sending links to colleagues.

Real-World Examples

These typical inputs and outputs occur every day:

  • Format with 2 spaces: {"a":1,"b":2} turns into multi-line {
    "a": 1,
    "b": 2
    }
    .
  • Minify a 100 KB API response: typical reduction to 60–80 KB, because indentation and line breaks are stripped. Over a year this measurably adds up on the server egress bill.
  • Nested object: {"user":{"name":"Anna","roles":["editor","author"]}} becomes three structured levels — you immediately see that roles is an array nested under user.
  • Error diagnosis: for {"a":1,} the validator reports "Unexpected token } in JSON at position 7" — trailing commas are forbidden.
  • Single-quote case: {'a':1} is not valid JSON. JavaScript object literals look like this, JSON however requires double quotes — the error reads "Expected property name or '}'".

Limits, Edge Cases and Security

Even a "simple" formatter has serious edge cases. First: number precision. JavaScript's JSON.parse turns numbers into IEEE-754 doubles. Values above 2^53 − 1 lose digits — 10765432109876543 can become 10765432109876544. If you process Snowflake or Twitter IDs, transmit them as strings. Second: strict mode mismatches. Trailing commas, comments, single quotes or unquoted keys are forbidden by RFC 8259 — browsers will not parse them. For such inputs use JSON5 or sanitize first. Third: Unicode escaping. JSON.stringify without a replacer writes non-ASCII through directly (UTF-8). When dealing with legacy systems you may need \uXXXX escaping — valid but not our tool's default. Fourth and security-critical: logging JSON with secrets. Pretty-printing makes bearer tokens and API keys readily visible in logs, screenshots or shared URLs. Mind the payload before copying or linking. Fifth: prototype pollution. JSON.parse itself is safe, but downstream Object.assign(config, parsed) can be attacked via __proto__ or constructor as keys to poison the global prototype — filter those keys or use Map instead.

Frequently Asked Questions about the JSON Formatter

Why do I get "Unexpected token" on a trailing comma?
RFC 8259 forbids trailing commas explicitly. {"a":1,} is illegal even though many editors would tolerate it. Drop the last comma or run a JSON5 parser. In the build, ESLint or Prettier should catch this automatically.
What is the difference between JSON and JSON5?
JSON5 is a superset that allows comments (// and /* */), trailing commas, single quotes, unquoted keys and hex numbers. It is more human-friendly for configs but not understood by JSON.parse. Babel, Webpack and ESLint use JSON5 for their config files.
How much do I really save by minifying?
For normally formatted JSON (2 spaces, line breaks) 20–40% is typical. Highly structured, deeply nested data saves more; compact arrays with short keys save less. Over HTTP, gzip/brotli also kicks in — measured on the wire, minify is often only worth another 5–10%.
Can I use comments in JSON?
Not in strict RFC 8259 JSON. Workarounds: JSONC (VSCode), JSON5, or a pseudo key like "_comment": "…" ignored by consumers. JSONC has become the de-facto standard for config files.
Which indentation should I use for my API responses?
For production APIs: minify, because every client (browser, mobile) can read it and bandwidth matters. For dev/staging logs: 2 spaces, because humans read them. Stay consistent — mixed styles complicate Git diffs.
Is my data stored anywhere when formatting?
No. Parsing, formatting and minify run entirely in JavaScript inside the browser. CalcSI sees neither content nor size of your data. The optional ?data= URL parameter stays local — it lives in the URL only, never sent to the server.

Related Tools

  • JSON Editor — Tree and table views, JSON Schema validation, JSONPath and JMESPath queries for deep editing.
  • YAML ↔ JSON Converter — Lossless conversion between YAML and JSON for configs, Docker Compose and CI pipelines.
  • CSV to JSON — Convert tabular CSV exports into JSON arrays and back, with RFC 4180 quoting.