Skip to content

JSON Prettier: Pretty Print JSON

JSON Prettier puts each key on its own line with the indent you choose, and can escape non-ASCII text when the target expects plain ASCII.

Input · JSON
object {7}
"name": "weather-widget"
"version": "1.3.0"
"private": true
"scripts": {3}
"dev": "vite"
"build": "vite build"
"test": "vitest run"
"dependencies": {2}
"date-fns": "^4.1.0"
"zod": "^3.24.1"
"devDependencies": {2}
"vite": "^6.0.7"
"vitest": "^3.0.2"
"engines": {1}
"node": ">=20"
Valid JSON7 top-level keys · depth 3 · 15 keysRuns in your browser

Load from a URL

Your browser fetches it directly, so the server must allow cross-origin requests (CORS).

How to pretty print JSON

  1. Paste JSON or press Open file.
  2. Pick an Indent: 2 spaces, 4 spaces or Tabs.
  3. Press Pretty print or Ctrl + Enter.

Example

{"city":"Zürich","station":"Hauptbahnhof","platform":"41/42","departures":[{"line":"S3","to":"Wetzikon","in":4,"price":4.40},{"line":"IR 75","to":"Konstanz","in":11,"price":31.00}],"note":"Gleis 41 → Ausgang Süd"}

With 2 spaces:

{
  "city": "Zürich",
  "station": "Hauptbahnhof",
  "platform": "41/42",
  "departures": [
    {
      "line": "S3",
      "to": "Wetzikon",
      "in": 4,
      "price": 4.40
    },
    {
      "line": "IR 75",
      "to": "Konstanz",
      "in": 11,
      "price": 31.00
    }
  ],
  "note": "Gleis 41 → Ausgang Süd"
}

The prices stay 4.40 and 31.00. JSON.stringify(JSON.parse(text), null, 2) prints 4.4 and 31, and Python’s json.dumps prints 4.4 and 31.0, because both convert the numbers; this page only re-indents the text. Duplicate keys survive too: both "status" lines stay, where JSON.parse keeps only the second.

Indentation costs bytes: the example is 217 bytes on one line, 287 with tabs, 325 with 2 spaces and 401 with 4. A tab is one character per level, shown at each editor’s own width. JSON minify puts it back on one line.

Escape non-ASCII

Escape non-ASCII writes every non-ASCII character, in keys and values, as a \u escape:

  "city": "Z\u00fcrich",
  "note": "Gleis 41 \u2192 Ausgang S\u00fcd"

Emoji and other characters beyond the Basic Multilingual Plane become a pair, like \ud83d\ude86. Both forms parse to the same string. The escaped one survives systems that mangle UTF-8 and matches Python’s default ensure_ascii=True output.

JSON inside a string

Logs often carry JSON as an escaped string, such as "{\"id\":7,\"tags\":[\"a\"]}". To a parser that is one string value, so pretty printing leaves it on one line. Unescape it first in JSON escape with Mode set to Unescape.

Pretty print JSON in code

If the input does not parse, the Report tab shows where it stops.

Questions

Is pretty printed JSON still valid?

Yes. JSON allows whitespace between keys, values and brackets, so a parser reads the indented and the one-line versions as the same data.

Should I use 2 spaces, 4 spaces or tabs?

Follow the files around it. Tabs make the smallest file of the three, and 4 spaces is what Python's json.tool prints by default.

Is pretty print the same as beautify or prettify?

Yes. Pretty print, beautify, prettify and format all mean adding line breaks and indentation without changing the data.

Is this the Prettier code formatter?

No. This page only indents JSON. Prettier is a separate code formatter that can also format the JSON files in a project.

Related tools

Esc