Skip to content

JSON Formatter

Indentation
Formatted JSON —
Objects
—
Arrays
—
Keys
—
Scalar values
—
Nesting depth
—
Output lines
—
Input characters
—
Output characters
—

Paste JSON and it is parsed with the strict RFC 8259 grammar, then rewritten with 2 spaces, 4 spaces, tabs or no whitespace at all. For example, { "a" : [ 1 , 2 ] } minifies to {"a":[1,2]}, 11 characters. Invalid input, such as a trailing comma, is reported with its line and column.

About this tool

API responses, log lines and config files often arrive as one long line of JSON that nobody can read. This formatter parses the text with the same strict grammar every browser uses, then prints it back with the indentation you pick, or squeezes it onto a single line for a request body. An option sorts every object's keys alphabetically, which turns two differently ordered payloads into text a diff tool can compare. Alongside the output it counts objects, arrays, keys, scalar values and nesting depth, so you can see the shape of a payload at a glance. It does not accept JSON5 or JavaScript extras: comments, single quotes and trailing commas are errors. Very large numbers beyond about 15 significant digits lose precision when parsed, as they do in any JavaScript program.

How to use it

  1. Paste or open the JSON

    Paste into the box or open a .json or .txt file from your device; it is read locally.

  2. Pick an indentation

    Choose 2 spaces, 4 spaces, tabs, or Minify for a single line with no whitespace.

  3. Sort keys if you need to compare

    Tick the sort option to order every object's keys alphabetically at all levels.

  4. Copy the output

    Use Copy result to take the formatted text, or read the error message to find a syntax problem.

Examples

Minify a spaced-out object

JSON
{ "a" : [ 1 , 2 ] }
Indentation
Minify
Sort object keys A to Z
No

Result Formatted JSON: {"a":[1,2]}
Objects: 1
Arrays: 1
Keys: 1
Scalar values: 2
Nesting depth: 2
Output lines: 1
Input characters: 19
Output characters: 11

  1. Parsed 19 characters as JSON (RFC 8259): 1 objects, 1 arrays, 2 scalar values.
  2. Wrote the result on one line with no whitespace: 11 characters.

All whitespace between tokens is dropped, leaving 11 characters with the same meaning.

Sort keys with 4-space indent

JSON
{"zeta":1,"alpha":{"y":true,"b":null},"mid":[1,2,3]}
Indentation
4 spaces
Sort object keys A to Z
Yes

Result Formatted JSON: {
"alpha": {
"b": null,
"y": true
},
"mid": [
1,
2,
3
],
"zeta": 1
}
Objects: 2
Arrays: 1
Keys: 5
Scalar values: 6
Nesting depth: 2
Output lines: 12
Input characters: 52
Output characters: 128

  1. Parsed 52 characters as JSON (RFC 8259): 2 objects, 1 arrays, 6 scalar values.
  2. Sorted object keys alphabetically, then wrote the result with 4-space indentation: 128 characters.

Keys come out as alpha, mid, zeta at the top level and b before y inside alpha, which makes two versions of a config easy to diff.

How it is calculated

output = serialise(parse(input), indent), with keys optionally sorted before serialising

parse
the strict JSON grammar of RFC 8259 and ECMA-404, as implemented by JSON.parse
indent
2 spaces, 4 spaces, one tab per level, or none for minified output
depth
the deepest level of nesting, where the top-level value is level 0

The text is parsed into values first, so formatting never changes the data: strings keep their escapes, numbers keep their value, and whitespace between tokens is simply discarded. Serialising then writes one member per line at the chosen indent. When a parse fails, the position reported by the parser is converted into a line and column.

When not to use it

  • JSON5, JSONC or files with comments, such as some editor settings, are rejected by the strict parser.
  • Integers longer than 15 or 16 digits, like some database IDs, can be altered by parsing and should be kept as strings.
  • Huge files of many megabytes are better handled by a command-line tool such as jq.

Common mistakes

  • Leaving a trailing comma after the last item in an object or array, which JSON does not allow.
  • Using single quotes around keys or strings; JSON requires double quotes.
  • Pasting a JavaScript object literal with unquoted keys and expecting it to parse as JSON.

Frequently asked questions

Does formatting change my data?

No. The JSON is parsed into values and written back out, so only whitespace changes. The one exception is very long integers: numbers beyond about 15 significant digits are stored as double-precision floats and may lose their last digits.

What happens to duplicate keys?

RFC 8259 leaves duplicate keys undefined. The parser here keeps the last value for a repeated key, so the formatted output contains that key once.

Why is my file rejected when my editor opens it fine?

Many editors read JSONC or JSON5, which allow comments, single quotes and trailing commas. Strict JSON allows none of those. The error message gives the line and column where parsing stopped.

Is sorting keys safe?

For JSON data it is: object members have no defined order in the specification, so sorting does not change meaning. Array order is kept as it is, because arrays are ordered.

How is nesting depth counted?

The top-level value is level 0 and each object or array adds one level for its contents. {"a":[1,2]} has depth 2 because the numbers sit inside an array inside an object.

Is the JSON sent to a server?

No. Parsing and formatting run in your browser, including when you open a file, so API keys or personal data in the payload stay on your device.

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 Formatter. Tools Directory. Retrieved October 28, 2026, from https://tools.milunir.com/developer-tools/json-tools/json-formatter/

MLA

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

Chicago

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

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