Format JSON

Format valid JSON with readable indentation, optional key sorting, and a trailing newline.

freeworks offlinenothing uploaded
ToolJSON Formatter
Inputempty
Output

How it works

The input is parsed and serialized with configurable indentation, optional key sorting, and optional trailing newline. Parsing first ensures the result is valid JSON rather than merely aligned text.

  • Two spaces are a common source-control convention.
  • Key sorting is off because human review order may matter.

Worked example

Minified to Pretty
Format a compact JSON object with 2-space indentation
Input
											{"name":"Alice","age":30,"roles":["admin","user"],"address":{"city":"Portland","state":"OR"}}
										
Output
												{
  "name": "Alice",
  "age": 30,
  "roles": [
    "admin",
    "user"
  ],
  "address": {
    "city": "Portland",
    "state": "OR"
  }
}
											

When to use this

API inspection, repository configuration, and documentation examples format JSON.

Edge cases

  • Whitespace inside strings remains unchanged.
  • Invalid escape sequences fail parsing rather than being repaired.
  • Sorting changes object display order but not array order.

References