Skip to content
Everyone-Website
How-to

How to Format JSON (Beautify, Minify, and Fix Errors)

Learn how to format JSON the right way: beautify it for reading, minify it for size, fix common syntax errors, and validate it. Free, no upload needed.

Updated 6 June 2026 5 min read

JSON is everywhere — API responses, config files, log lines — and it is easy to read until it arrives as one giant unbroken line. This guide shows you how to format JSON so humans can read it, shrink it for transfer, and fix the syntax errors that make parsers choke.

What is JSON (and why “format” it)?

JSON (JavaScript Object Notation) is a plain-text format for structured data. Despite the name, it is language-independent and used almost everywhere data needs to move between systems.

JSON is built from a small set of value types:

  • Objects — unordered key/value pairs wrapped in { }
  • Arrays — ordered lists of values wrapped in [ ]
  • Strings — text in double quotes, like "hello"
  • Numbers — like 42, -3.14, or 2.5e3
  • Booleanstrue or false
  • null — represents an empty or missing value

Here is a small but complete example using all of them:

{
  "name": "Ada",
  "age": 36,
  "active": true,
  "nickname": null,
  "skills": ["math", "logic"]
}

“Formatting” JSON means changing the whitespace — the spaces, tabs, and line breaks between tokens — without changing the data itself. You do this either to make JSON readable (beautify) or compact (minify).

Beautify vs minify

These are the two directions you can format JSON in. The data is identical; only the spacing differs.

Beautify (pretty-print)Minify (compact)
LayoutIndented, multi-lineSingle line, no extra spaces
Best forReading, debugging, diffingStorage, network transfer
File sizeLargerSmaller
Human-friendlyYesNot really

Beautified JSON is indented and spread across multiple lines so you can scan the structure:

{
  "id": 7,
  "tags": ["a", "b"],
  "meta": { "ok": true }
}

Minified JSON is the same data with all non-essential whitespace removed:

{"id":7,"tags":["a","b"],"meta":{"ok":true}}

For a tiny snippet the savings look trivial, but across large payloads — or thousands of API calls — stripping whitespace meaningfully reduces bytes transferred and speeds things up. In production you minify; while debugging you beautify.

How to format JSON with our tool

The fastest way is to use our free JSON formatter. It runs entirely in your browser — nothing is uploaded to a server, so it is safe to paste sensitive data like tokens or internal API responses.

  1. Paste your JSON into the input box.
  2. Click Beautify to indent and expand it, or Minify to compact it onto one line.
  3. If there is a syntax error, the tool tells you what went wrong and where.
  4. Copy the result with one click.

That round trip — paste, beautify, fix any flagged errors, copy — covers the vast majority of day-to-day JSON cleanup.

Common JSON syntax errors (and how to fix them)

Most “invalid JSON” problems come from a handful of mistakes. Standard JSON is stricter than JavaScript object literals, which trips up a lot of people. Here are the usual culprits.

Trailing commas

A comma after the last item in an object or array is not allowed in JSON.

Wrong:  { "a": 1, "b": 2, }
Right:  { "a": 1, "b": 2 }

The same applies to arrays: [1, 2, 3,] is invalid; remove the final comma.

Single quotes instead of double quotes

JSON strings and keys must use double quotes ("). Single quotes are valid in JavaScript but not in JSON.

Wrong:  { 'name': 'Ada' }
Right:  { "name": "Ada" }

Unquoted keys

Keys are always strings, so they always need double quotes — even simple ones with no spaces.

Wrong:  { name: "Ada" }
Right:  { "name": "Ada" }

Missing commas between items

Every pair or element needs a comma separating it from the next one.

Wrong:  { "a": 1 "b": 2 }
Right:  { "a": 1, "b": 2 }

Mismatched or missing brackets and braces

Every { needs a matching }, and every [ needs a matching ]. A common error is closing an object with the wrong symbol:

Wrong:  { "list": [1, 2, 3 }
Right:  { "list": [1, 2, 3] }

Beautifying first makes these much easier to spot, because the indentation visually lines up opening and closing pairs.

Comments are not allowed

Standard JSON has no comments — neither // nor /* */. This surprises people coming from JavaScript or config formats like JSONC.

Wrong:
{
  // user record
  "name": "Ada"
}

Right:
{
  "name": "Ada"
}

If you need annotations, store them as a real key (for example "_comment": "user record") or use a format that explicitly supports comments, like JSONC or YAML.

Using undefined or NaN

JSON only allows the value types listed earlier. JavaScript values like undefined, NaN, and Infinity are not valid JSON.

Wrong:  { "value": undefined, "score": NaN }
Right:  { "value": null, "score": 0 }

Decide what each one should mean: use null for “no value,” or a real number where one is required.

Validating JSON

Validating just means checking that text is well-formed JSON that a parser can read. A formatter does this automatically: when you paste invalid JSON, parsing fails, and the tool reports the error — usually with a position or line number pointing at the problem.

That feedback is the quickest way to debug a payload. Instead of hunting character by character, you paste, read the error message (for example Unexpected token } at position 24), jump to that spot, and fix it. Repeat until it validates cleanly, then beautify or minify as needed.

A few tips

  • Use consistent indentation. Pick 2 spaces or 4 spaces and stick with it across a project. Beautifiers let you standardize an inconsistent file in one click.
  • Keep keys consistent. Choose a casing convention — snake_case, camelCase, or lowercase — and apply it everywhere. Mixed styles like userName next to user_id cause subtle bugs.
  • Validate API responses. Before assuming an endpoint is broken, paste its response into a formatter. You will quickly see whether you got valid JSON, an error page, or HTML by mistake.
  • Beautify to debug, minify to ship. Read and diff the pretty version; send the compact one.

Ready to clean up a payload? Open our free JSON formatter, paste your data, and beautify, minify, or validate it in one click — all in your browser.