FTJ
← Blog
Developer

How to Format JSON: Fix Messy JSON in Seconds

Got a wall of unindented JSON and can't read it? Here's how to clean it up fast — no install, no signup, just paste and format.

I debug API responses for a living. Half my job is staring at JSON like {"user":{"id":42,"roles":["admin","editor"]},"active":true} and trying to figure out where the nesting breaks. A JSON formatter is not a luxury — it's the first tool I reach for.

Why Bother Formatting JSON?

Raw JSON from APIs and logs comes compressed into a single line. The structure is there, but your eyes can't parse it. Formatting adds indentation and line breaks so you can actually see the shape of the data:

Before (single line): {"user":{"id":42,"roles":["admin","editor"]},"active":true}

After (formatted): { "user": { "id": 42, "roles": ["admin", "editor"] }, "active": true }

The second version tells you immediately: user is an object with id and roles, and there's a sibling active flag. The first version tells you nothing at a glance.

What a Formatter Actually Does

Three things, and they're distinct:

  1. Pretty-prints — adds indentation (usually 2 spaces) and line breaks
  2. Validates — if your JSON has a syntax error, the formatter tells you where
  3. Minifies — the reverse: strips whitespace to make the payload smaller

I use minification when sending JSON over the wire (smaller payload = faster request) and formatting when debugging (readable structure = faster diagnosis).

How to Use the Formatter On This Site

  1. Paste your JSON into the input area
  2. Click Format for readable indentation, or Minify for compact output
  3. If there's a syntax error, you'll see the error message with the position
  4. Copy the result

The JSON formatter runs entirely in your browser — nothing gets sent to a server. I built it that way because pasting production API keys into a random online tool is a bad habit.

## JSON Formatting Standards

Properly formatted JSON follows these conventions:

  • 2-space indentation: The most common standard. Some teams prefer 4 spaces or tabs, but 2 spaces is the de facto default.
  • No trailing commas: JSON does not allow trailing commas. {"a": 1,} is invalid and will be rejected by parsers.
  • Double quotes only: Keys and string values must use double quotes. Single quotes are not valid JSON.
  • No comments: Standard JSON does not support comments. Some parsers (like JSON5) allow them, but they break standard parsers.
  • UTF-8 encoding: JSON should be UTF-8 encoded. Other encodings may cause issues with non-ASCII characters.

JSON Validation Errors

Common errors and their causes:

  • Unexpected token: Usually a missing comma, extra comma, or mismatched bracket. The error position tells you where the parser failed.
  • Unexpected end of input: A missing closing bracket or brace. The parser reached the end of the file while still inside a nested structure.
  • Duplicate keys: Technically valid JSON, but most parsers keep only the last value. This is almost always a mistake.
  • Control characters: Literal newlines and tabs inside strings are invalid. Use \n and \t escape sequences instead.

JSON in APIs

When working with REST APIs, JSON formatting matters for debugging but not for transmission. Most API clients and servers minify JSON in transit to save bandwidth. Tools like Postman, curl, and httpie automatically format JSON responses for display.

If you are debugging an API, paste the response into our JSON Formatter to make it readable. The formatter also validates syntax, so malformed responses are immediately obvious.

Try These Tools

More Articles