Skip to content

JSON Beautifier

Indent
Beautified JSON —
Lines
—
Nesting depth
—
Objects
—
Arrays
—
Keys
—
Input characters
—
Output characters
—

A JSON beautifier parses minified or messy JSON and prints it again with one member per line and consistent indentation. Paste {"a":1,"b":[1,2]} with 2-space indent and you get seven lines, the array elements two levels deep. Invalid input, such as a trailing comma, is reported with its line and column instead of being formatted.

About this tool

API responses, log lines and config exports usually arrive as a single dense line of JSON that is hard to read or review. This beautifier parses the text with the strict JSON grammar and prints it back with the indentation you pick: two spaces, four spaces or a tab. You can also sort object keys alphabetically at every level, which helps when comparing two payloads. Alongside the output it reports line count, nesting depth, how many objects, arrays and keys the document holds, and the character count before and after. Parsing happens in your browser, so the text is not uploaded. One limit: numbers are read as standard double-precision values, so integers longer than about 15 to 17 digits, such as some database IDs, can change unless they are stored as strings.

How to use it

  1. Paste or open the JSON

    Paste text into the JSON box, or use Open a text file to load a .json file from your computer.

  2. Choose the indent

    Pick 2 spaces, 4 spaces or Tab to match your project's style guide or editor settings.

  3. Optionally sort keys

    Tick Sort object keys A to Z to order every object's members alphabetically; array order is never changed.

  4. Read the result and counts

    Copy the beautified JSON, check the nesting depth and key count, or fix the line and column named in the error.

Examples

A one-line object with an array

JSON
{"a":1,"b":[1,2]}
Indent
2 spaces
Sort object keys A to Z
No

Result Beautified JSON: {
"a": 1,
"b": [
1,
2
]
}
Lines: 7
Nesting depth: 2
Objects: 1
Arrays: 1
Keys: 2
Input characters: 17
Output characters: 39

  1. Parsed 17 characters as JSON: 1 objects, 1 arrays, 2 keys.
  2. Kept keys in their original order.
  3. Printed with 2-space indentation: 7 lines, 39 characters.

Seventeen characters of minified JSON open up into seven lines; the array elements sit two levels deep.

A config file with sorted keys

JSON
{"server":{"port":8080,"host":"localhost"},"debug":true}
Indent
4 spaces
Sort object keys A to Z
Yes

Result Beautified JSON: {
"debug": true,
"server": {
"host": "localhost",
"port": 8080
}
}
Lines: 7
Nesting depth: 2
Objects: 2
Arrays: 0
Keys: 4
Input characters: 56
Output characters: 94

  1. Parsed 56 characters as JSON: 2 objects, 0 arrays, 4 keys.
  2. Sorted object keys alphabetically at every level.
  3. Printed with 4-space indentation: 7 lines, 94 characters.

Sorting puts debug before server and host before port, which makes two versions of a config easy to compare line by line.

How it is calculated

output = JSON.stringify(JSON.parse(input), null, indent)

input
the pasted text, with a leading byte order mark removed
indent
2 or 4 spaces, or one tab character per nesting level
depth
the deepest level reached, counting the top-level value as 0

The text is parsed against the JSON grammar in RFC 8259, which rejects comments, single quotes, trailing commas and unquoted keys. The parsed value is then serialised again following the ECMAScript JSON.stringify rules: each object member and array element goes on its own line, indented once per level, with a space after every colon. Empty objects and arrays stay as {} and []. When sorting is on, keys are ordered by their character codes before printing, so uppercase letters come before lowercase.

When not to use it

  • JSON5 or JSONC files with comments will be rejected, because the strict grammar has no comments.
  • Payloads with very long integer IDs stored as numbers may lose digits during parsing.
  • Files of many megabytes are better handled by a command-line tool such as jq.

Common mistakes

  • Pasting a JavaScript object literal with single quotes or unquoted keys, which is not JSON.
  • Leaving a trailing comma after the last item in an object or array.
  • Expecting key sorting to reorder arrays; only object members are sorted.

Frequently asked questions

Why does my JSON show an error with a line and column?

The parser stops at the first character that breaks the JSON grammar and reports where it is. Common causes are a trailing comma, a missing quote, a single-quoted string or a comment. Fix that spot and the formatted output appears as you type.

Does beautifying change the data?

No values or key order change unless you turn on sorting. Whitespace between tokens is replaced, and escape sequences may be normalised, for example \u0041 is printed as A. The one exception is very long numbers, which are limited to double precision.

Should I use 2 spaces, 4 spaces or tabs?

It is a style choice. Two spaces is the default in npm's package.json and most JavaScript projects, four spaces matches Python's json.dumps examples and many Java codebases, and tabs let each reader set their own width in the editor.

What does nesting depth tell me?

It is how many levels of objects or arrays you pass through to reach the deepest value, with the top level counted as 0. A flat list of records has depth 2. Very deep structures are harder to query and sometimes hit parser limits in other systems.

What happens to duplicate keys?

RFC 8259 says object names should be unique but does not forbid duplicates. When a key repeats, the parser keeps the last value, so the beautified output shows only one copy. Check the source if the key count is lower than you expected.

Is my JSON sent anywhere?

No. Parsing and formatting run in the page's script in your browser, and a file opened with the file button is read locally. Nothing is uploaded, which matters when the payload contains tokens or customer data.

Cite this tool

Using this tool in an assignment, article or report? Copy a citation, or a link for your website.

APA

Tools Directory Editorial Team. (2026, October 28). JSON Beautifier. Tools Directory. Retrieved October 28, 2026, from https://tools.milunir.com/developer-tools/json-tools/json-beautifier/

MLA

Tools Directory Editorial Team. “JSON Beautifier.” Tools Directory, 28 Oct. 2026, https://tools.milunir.com/developer-tools/json-tools/json-beautifier/. Accessed 28 Oct. 2026.

Chicago

Tools Directory Editorial Team. “JSON Beautifier.” Tools Directory. Last modified October 28, 2026. Accessed October 28, 2026. https://tools.milunir.com/developer-tools/json-tools/json-beautifier/.

Link<a href="https://tools.milunir.com/developer-tools/json-tools/json-beautifier/">JSON Beautifier – Tools Directory</a>