JSON Formatter

You know the moment. An API hands you a response that’s one endless line — or a config file throws an error and won’t tell you where. Paste that JSON in here and it comes back clean: indented, readable, and checked. Pick 2 or 4 spaces, click Format, and the structure is suddenly visible at a glance.

It goes the other way too. Minify strips formatted JSON back to a single line, and Validate checks your text without changing it — if something’s broken, you get the parser’s real error message plus the exact line and column to look at. Two newer helpers round it out: a Sort keys option that puts every object’s keys in A–Z order (handy when you’re comparing two files), and a structure line in the stats that tells you what you just pasted — an object with 3 top-level keys, say, nested 3 levels deep.

When you’re done, copy the result, copy a minified version in one click, or download it as a .json file. Nothing is uploaded and nothing is stored — the whole job happens in the tab you already have open.

Developer reviewing neatly formatted JSON on a screen, cleaned up with a JSON formatter

JSON Formatter

Paste messy JSON below to format it with clean indentation, minify it back to one line, sort its keys, or validate it and see exactly where an error is.

Status: — Structure: — Input size: 0 characters Output size: 0 characters

This tool runs entirely in your browser using JavaScript’s built-in JSON parser — your JSON is never uploaded, sent anywhere, or stored.

How it works

Under the hood it’s JavaScript’s built-in JSON parser — the same strict parser your browser uses for web apps. Format parses your input to confirm it’s valid, then re-prints it with consistent indentation. Minify does the reverse, removing every unnecessary space and line break. Validate parses only, and reports the result.

Sorting deserves a word of its own, because it changes the output without changing the data. With Sort keys ticked, the tool walks every object in your document — including objects nested inside other objects — and rewrites its keys in alphabetical order. Arrays are never reordered, and no value is touched. That’s exactly what you want before running two versions of a file through a diff tool: same data, same order, so the differences that matter stop hiding behind key order.

The structure line is computed from the parsed data each time you format, minify or validate. It shows the root type (object, array, or a single value), the number of top-level keys or items, and the maximum nesting depth.

Now the honest limits. This is a formatter and validator, not a JSON editor: it won’t repair broken JSON, guess what you meant, or check your data against a schema. It also won’t convert JSON to CSV or YAML — that’s a separate job with its own tool. And there’s no collapsible tree view; the structure line gives you the shape at a glance, but for browsing a huge file node by node, a desktop editor is the better fit.

How to use it

  1. Paste your JSON into the input box (or click “Load sample” to try it with an example).
  2. To beautify it, pick an indent size — 2 spaces or 4 spaces — and click Format. The formatted result appears in the Result box.
  3. Comparing two files? Tick Sort keys A–Z before you format, and every object’s keys come out in alphabetical order.
  4. To compress JSON into one line, click Minify.
  5. To check validity without changing anything, click Validate. You get either a confirmation or the parser’s error message with its position, line and column.
  6. Check the stats line for the status, the structure summary, and the input/output sizes.
  7. Click Copy result to copy what’s in the Result box, Copy minified to copy a one-line version in a single click, or Download .json to save the result as a file. Clear starts over.

Worked example

A developer receives this minified response from an API:

{"user":{"id":42,"name":"Ayesha","roles":["editor","admin"]},"active":true,"score":98.5}

After clicking Format with 2-space indentation, it becomes:

{
  "user": {
    "id": 42,
    "name": "Ayesha",
    "roles": [
      "editor",
      "admin"
    ]
  },
  "active": true,
  "score": 98.5
}

The structure — which keys belong to which object, and where the array starts and ends — is now visible at a glance. The stats row describes the shape in words: Object · 3 top-level keys · depth 3.

Tick Sort keys A–Z and format again, and the same data comes back with its keys reordered — active, score, then user at the top level, and id, name, roles inside it. Nothing else changes. And clicking Minify on the formatted version returns the original single line exactly.

Who it is for

  • Developers and QA testers reading API responses, webhook payloads, and log output.
  • Students learning JSON who need to see nesting and structure clearly.
  • Anyone handling config files (for example package.json-style data) who wants consistent indentation — or a stable key order — before committing or sharing.
  • Privacy-conscious users: API responses often contain real user data or tokens, and with this tool that data never leaves your machine.

Why use this tool

  • Format, minify and validate in one place — beautify with 2 or 4 spaces, compress back to a single line, or check validity without changing a character.
  • Errors you can act on — when JSON is broken, you get the parser’s real message plus the exact line and column, not a vague failure.
  • Sort keys for clean diffs — every object’s keys come out in A–Z order (arrays untouched), so two versions of a file compare line by line.
  • Take the result with you — copy the formatted result, copy a minified version in one click, or download it as a .json file.

Frequently Asked Questions

Is my JSON uploaded to a server?

No. The formatting and validation happen entirely in your browser using its built-in JSON parser. Nothing you paste is uploaded, logged, or stored, so it is safe to use with API responses that contain private data — though you should still follow your organisation’s data policies.

What is the difference between a formatter and a validator?

A validator only answers one question: is this valid JSON or not? A formatter also rewrites valid JSON with consistent indentation and line breaks so it is easy to read. This tool does both — and Format will refuse invalid JSON and show you the error instead of guessing.

What causes an “Unexpected token” error?

Usually one of a few small mistakes: a missing comma between items, a trailing comma after the last item (JSON does not allow them), single quotes instead of double quotes, unquoted key names, or a bracket that was never closed. The error position and the line/column shown by this tool point at the character where the parser gave up, so check just before that spot first.

How is JSON different from a JavaScript object?

They look similar, but JSON is a stricter text format: all keys must be in double quotes, strings must use double quotes, and values can only be strings, numbers, booleans, null, arrays, or objects — no functions, no undefined, no comments, and no trailing commas. A JavaScript object literal allows all of those extras, which is why code copied from JavaScript often fails as JSON.

Why would I minify JSON?

Minified JSON removes every unnecessary space and line break, making the data smaller to store or send. It is the format most APIs actually exchange. Developers minify before embedding JSON in a request, a file, or documentation where space matters — and format it again when they need to read it.

Can it handle large JSON files?

Yes, ordinary API responses and config files of any realistic size format instantly. Extremely large pastes (many megabytes) depend on your device and browser and may take a moment; if a file is tens of megabytes, a desktop editor will handle it more comfortably.

Is my JSON uploaded to a server?

No. The formatting and validation happen entirely in your browser using its built-in JSON parser. Nothing you paste is uploaded, logged, or stored, so it is safe to use with API responses that contain private data — though you should still follow your organisation’s data policies.

What is the difference between a formatter and a validator?

A validator only answers one question: is this valid JSON or not? A formatter also rewrites valid JSON with consistent indentation and line breaks so it is easy to read. This tool does both — and Format will refuse invalid JSON and show you the error instead of guessing.

What causes an “Unexpected token” error?

Usually one of a few small mistakes: a missing comma between items, a trailing comma after the last item (JSON does not allow them), single quotes instead of double quotes, unquoted key names, or a bracket that was never closed. The error position and the line/column shown by this tool point at the character where the parser gave up, so check just before that spot first.

How is JSON different from a JavaScript object?

They look similar, but JSON is a stricter text format: all keys must be in double quotes, strings must use double quotes, and values can only be strings, numbers, booleans, null, arrays, or objects — no functions, no undefined, no comments, and no trailing commas. A JavaScript object literal allows all of those extras, which is why code copied from JavaScript often fails as JSON.

Why would I minify JSON?

Minified JSON removes every unnecessary space and line break, making the data smaller to store or send. It is the format most APIs actually exchange. Developers minify before embedding JSON in a request, a file, or documentation where space matters — and format it again when they need to read it.

Can it handle large JSON files?

Yes, ordinary API responses and config files of any realistic size format instantly. Extremely large pastes (many megabytes) depend on your device and browser and may take a moment; if a file is tens of megabytes, a desktop editor will handle it more comfortably.