JSON Formatter & Beautifier

Output
Indent:
Examples:

Last updated: 2026-09-17

Paste or type JSON into the editor and get instantly beautified output with syntax highlighting, bracket matching, and line numbers. Everything runs locally in your browser — your data never touches a server.

What this tool does

Takes minified or raw JSON and produces beautified output with configurable indentation (2 spaces, 4 spaces, or tabs). Optional features include sorting keys alphabetically and escaping non-ASCII characters to \uXXXX sequences. The output is valid JSON that any parser can read.

Example

Input (minified):

{"status":"ok","data":{"users":[{"id":1,"name":"Alice"},{"id":2,"name":"Bob"}],"total":2}}

Output (2-space indent):

{
  "status": "ok",
  "data": {
    "users": [
      { "id": 1, "name": "Alice" },
      { "id": 2, "name": "Bob" }
    ],
    "total": 2
  }
}

Options

OptionDefaultEffect
Indentation2 spacesControls how many spaces (or tab) per nesting level
Sort keysOffAlphabetically sorts object keys at all levels
Escape UnicodeOffReplaces non-ASCII with \uXXXX sequences

Formatting API responses for debugging

When you fetch data from a REST or GraphQL API, the response body is usually minified to save bandwidth. A single-line blob with no spaces is efficient on the wire but impossible to read. Pasting it into the formatter makes the structure visible immediately.

Consider a paginated users endpoint that returns the following minified payload:

{"page":1,"per_page":3,"total":128,"pages":43,"users":[{"id":42,"name":"Alice","email":"alice@example.com","roles":["admin","editor"],"last_login":"2026-09-10T14:22:01Z"},{"id":43,"name":"Bob","email":"bob@example.com","roles":["viewer"],"last_login":"2026-08-30T09:15:44Z"},{"id":44,"name":"Carol","email":"carol@example.com","roles":["editor","viewer"],"last_login":null}]}

After formatting with 2-space indentation you can see the pagination envelope at the top level, the users array as a distinct block, and each user’s fields aligned vertically. When a bug report says the third user is missing roles, formatted output lets you scan to index 2 and inspect the roles array without scrolling horizontally. If the API also returns unexpected fields or nulls where you expected strings, the aligned columns make those anomalies obvious within seconds.

For responses wrapped in a top-level envelope — a common pattern with meta, data, and errors siblings — formatting separates each section onto its own lines so you can check whether errors populated alongside data, which is a frequent source of silent failures in client code.

Formatting package.json

A package.json file accumulates entries over time: dependencies, devDependencies, scripts, config blocks. When several properties sit on compressed lines, spotting a duplicate dependency or checking a version range means reading carefully. Formatting puts each property and each dependency on its own line.

Take this compact scripts block:

{"scripts":{"build":"tsc","test":"vitest","lint":"eslint src","dev":"vite"},"dependencies":{"express":"4.18.2","cors":"2.8.5"},"devDependencies":{"typescript":"5.3.0","vitest":"1.0.0"}}

Formatted, every script and dependency gets its own line. Enabling sort keys alphabetizes the dependencies so express and cors sit next to each other instead of appearing in insertion order. This helps before a code review: reviewers can scan the sorted list, spot an unexpected package, and verify the version without hunting through a long unsorted block.

Formatting package.json is also useful when trimming unused dependencies. With each package on its own line you can tick them off against your import statements more quickly than when they are packed into a single line. Note that JSON formatting does not sort arrays like the scripts entry — only object keys are reordered when sort keys is enabled.

Formatting vs minifying vs validating

These three operations solve different problems and you should pick the right one for the task.

Formatting adds whitespace — indentation, newlines, spaces around structural punctuation — so a human can read and edit the data. Use it when you are debugging an API response, reviewing a config file, or hand-editing a manifest. The output is larger than the input but far easier to work with.

Minifying does the reverse: it strips every optional whitespace character to produce the smallest valid byte sequence. Use it before serving JSON over HTTP, embedding it in a bundle, or storing it where disk or memory footprint matters. Minified JSON is harder to read but faster to transmit. This tool does not minify — its purpose is readability, not compression.

Validating checks whether a string is syntactically correct JSON without producing transformed output. Use it when a downstream parser throws a cryptic error and you need to find the offending token. This tool validates incidentally: it calls JSON.parse on your input, and if parsing fails the error message — including the line and column where the parser stopped — is displayed. So formatting and validating happen together: valid input gets beautified, invalid input gets an error.

Common mistakes when formatting

How indentation affects readability

Indentation is the primary visual signal for nesting depth in JSON. The choice between 2 spaces, 4 spaces, and tabs affects how comfortably you can scan a document.

2 spaces is the dominant convention in the JavaScript and Node.js ecosystems. Most linters, formatters, and style guides default to it. The advantage is density: each nesting level adds only two characters, so even four levels deep the content stays within a typical editor width. The trade-off is that two characters can be subtle — at a glance, three levels and four levels look similar.

4 spaces doubles the visual step. Each level is unmistakable, which helps when you are tracing a path through a deeply nested response or comparing alignment across sibling objects. The cost is horizontal space: a four-level-deep array of objects with long property names can push content far to the right, causing wrapping on narrow screens or in side-by-side diff views.

Tabs let each reader configure their own display width in their editor — one person sees 2 spaces, another sees 8. This flexibility is useful in mixed-team settings. The downside is portability: when tab-indented JSON is pasted into a chat message, a terminal, or a Markdown code block, the tab width is controlled by the rendering application, which may display it as 8 spaces or as a single space. For JSON that will be shared in prose or pasted into documentation, spaces render identically everywhere.

Sorting keys for diffing

Object key order in JSON is not semantically meaningful — the specification defines objects as unordered — but most serializers preserve the order keys were inserted. When you diff two JSON files produced by different code paths, different key order generates noise: lines appear as removed and re-added even though the values are identical.

Enabling sort keys before formatting eliminates that noise. Both files get the same alphabetical key order at every nesting level, so a line-by-line diff only flags genuine value changes. This is useful in several scenarios:

Sorting is purely cosmetic from a data perspective. JSON.parse produces the same in-memory object regardless of key order, so sorted output parses to the same values as the original. The only difference is the byte sequence on disk or in the editor.

Do it in code

JavaScript:

const formatted = JSON.stringify(JSON.parse(input), null, 2);
// With sorted keys:
const sorted = JSON.stringify(
  Object.keys(JSON.parse(input)).sort().reduce((o, k) => (o[k] = obj[k], o), {}),
  null, 2
);

Python:

import json
formatted = json.dumps(json.loads(input), indent=2)
# With sorted keys:
sorted_output = json.dumps(json.loads(input), indent=2, sort_keys=True)

CLI:

# Python
echo '{"a":1,"b":2}' | python -m json.tool

# jq (2-space)
echo '{"a":1,"b":2}' | jq '.'

# jq (4-space)
echo '{"a":1,"b":2}' | jq --indent 4 '.'

Edge cases handled

Frequently asked questions

What is JSON formatting?
JSON formatting (or beautifying) adds indentation and line breaks to minified JSON so it is readable by humans. The data itself is not changed — only whitespace is added between tokens. The output is still valid JSON.
Does formatting change my data?
No. Formatting only adds whitespace. The parsed values, keys, and structure remain identical. If you enable sort keys, the key order changes but the data is semantically the same. Numbers, strings, booleans, and null are all preserved exactly.
What indentation should I use?
2 spaces is the most common convention for JSON, used by most linters and formatters. 4 spaces is easier to read for deeply nested data. Tabs are supported but can render inconsistently across editors. Choose whichever your project's style guide specifies.
Can I format very large JSON files?
Yes. Files over 200KB are processed in a Web Worker so the UI stays responsive. The editor uses CodeMirror which handles large documents efficiently. You can also drag and drop .json files onto the page.
What is the sort keys option?
Sort keys alphabetically reorders all object keys at every nesting level. This is useful for diffing two JSON files or creating deterministic output for caching. Without sorting, keys remain in their original insertion order.
What does escape Unicode do?
It replaces non-ASCII characters with their Unicode escape representation, which uses the letter u followed by four hexadecimal digits. This produces pure ASCII output that is safe for legacy systems that do not handle UTF-8 correctly. The data is semantically identical — only the byte representation changes.
How do I format JSON in the command line?
Use python with its json.tool module to pretty-print JSON piped through stdin. For more control, use jq with a dot filter and an indent flag. Both tools produce formatted output with configurable indentation.
Is my data sent to a server?
No. All parsing and formatting runs in your browser. The editor content stays on your machine and is never uploaded. This makes the tool safe for sensitive data such as configuration files, credentials, or API responses containing personal information.

Related tools