JSON Beautifier

Updated . The rules cited are from RFC 8259, the Python documentation and MDN, listed at the bottom.

Paste minified or messy JSON and get it back indented and readable. Choose 2, 3, 4 or 8 spaces or a tab, sort every object's keys, keep short arrays on one line, and show \u escapes as the characters they stand for. Only the layout changes: numbers, strings, key order and duplicate keys come out exactly as you wrote them. Nothing you paste or open is uploaded.

Quick answer. Paste your JSON and press Beautify; the result also follows the text and every option as you change them. Pick the indent, then tick Sort keys to order each object's keys, Keep short arrays on one line for compact lists, or Show \u escapes as characters to read non-English text. Copy the result or download it as a .json file. The compact example in the box is 136 bytes and becomes 232 bytes on 21 lines when beautified with two spaces.

JSON beautifier

Your text: 136 bytesBeautified: 232 bytes21 lines
2 objects3 arrays8 keys11 values3 levels deep

What a JSON beautifier does

A JSON beautifier takes JSON written compactly, usually on one line as an API sends it, and writes it out with a line break after every value and an indent for every level of nesting, so the structure can be read. It is also called pretty printing or formatting, and minifying is the reverse. Beautifying changes only whitespace, which RFC 8259 allows before or after any of the six structural characters (the brackets, the braces, the colon and the comma), so the data is the same before and after.1 A compact response:

{"order":{"id":1042,"items":[{"sku":"A-17","qty":2},{"sku":"B-03","qty":1}],"total":48.50,"paid":false}}

Beautified with two spaces:

{
  "order": {
    "id": 1042,
    "items": [
      {
        "sku": "A-17",
        "qty": 2
      },
      {
        "sku": "B-03",
        "qty": 1
      }
    ],
    "total": 48.50,
    "paid": false
  }
}

Beautifying needs valid JSON to start from. If the text is not valid, this page says where it stops, with the line, the column and a hint, and Fix common mistakes repairs the usual causes: comments, trailing commas, single quotes, unquoted keys and Python's True and None. For a plain verdict without the layout, use the JSON validator; for a collapsible tree and a larger set of examples of what goes wrong, see the JSON formatter.

The options, with examples

Indent

The indent is the width of one level: 2, 3, 4 or 8 spaces, or a tab. It is a matter of style, so use whatever the file you are pasting into already uses. Python's json.tool indents by 4 spaces unless you pass --indent or --tab (checked with Python 3.12), and JSON.stringify indents by whatever you pass it, up to 10.2 3

Sort keys

Sort keys puts the keys of every object in order, at every level. Keys are compared by their UTF-16 code units, which for ordinary text means capitals before lower-case letters, and two equal keys keep their original order. Arrays are never reordered, because the order of an array is part of the data. Sorting is most useful before comparing two documents with a diff tool. A document with its keys out of order:

{"b": 2, "a": {"z": 1, "y": 2}, "c": [3, 1]}

Sorted:

{
  "a": {
    "y": 2,
    "z": 1
  },
  "b": 2,
  "c": [
    3,
    1
  ]
}

Keep short arrays on one line

A list of numbers or tags takes one line per item when beautified, which makes a short list as tall as a long one. This option keeps an array on one line when it holds only plain values (strings, numbers, true, false or null) and the line would be at most 60 characters. A longer array, and any array that holds an object or another array, is laid out as usual. The same document with the option off:

{
  "name": "Ada",
  "tags": [
    "json",
    "tools",
    "free"
  ],
  "point": [
    23.588,
    58.382
  ],
  "history": [
    1,
    2,
    3,
    5,
    8,
    13,
    21,
    34,
    55,
    89,
    144,
    233,
    377,
    610,
    987,
    1597,
    2584
  ]
}

With it on, the short lists stay compact and the long one still breaks up:

{
  "name": "Ada",
  "tags": ["json", "tools", "free"],
  "point": [23.588, 58.382],
  "history": [
    1,
    2,
    3,
    5,
    8,
    13,
    21,
    34,
    55,
    89,
    144,
    233,
    377,
    610,
    987,
    1597,
    2584
  ]
}

Show \u escapes as characters

Some programs write every non-ASCII character as a \uXXXX escape: Python's json.dumps does by default, which turns Arabic, accented letters and emoji into runs of hexadecimal digits.2 The escapes are valid and mean the same thing, but nobody can read them. This option shows each one as the character itself. The value of every string stays the same; only the way it is written changes, and the result parses to exactly the data you put in. Arabic, an accented letter, a symbol and an emoji, with a non-breaking space and a zero-width joiner that stay escaped, as it is written:

{
  "city": "\u0645\u0633\u0642\u0637",
  "hello": "\u0645\u0631\u062d\u0628\u0627",
  "cafe": "Caf\u00e9",
  "price": "\u20ac5",
  "smile": "\ud83d\ude00",
  "gap": "a\u00a0b\u200dc"
}

With the option on:

{
  "city": "مسقط",
  "hello": "مرحبا",
  "cafe": "Café",
  "price": "€5",
  "smile": "😀",
  "gap": "a\u00a0b\u200dc"
}

Only characters that are safe to show are decoded: letters, marks, numbers, punctuation and symbols. Anything that would be invisible, ambiguous or unsafe stays as an escape, with its original digits and letter case:

What Show \u escapes as characters leaves escaped, and why
Stays escapedWhyExamples
Control charactersThey are invisible, and RFC 8259 requires U+0000 to U+001F to be escaped in a string.\u0000 \u001f \u007f \u0085
The quotation mark and the backslashThey cannot be written bare inside a string.\u0022 \u005c
Spaces other than a plain spaceA non-breaking or ideographic space looks like a space but is not one, and it would be invisible in the result.\u00a0 \u2003 \u3000
Invisible formatting charactersA zero-width joiner, a right-to-left override or a byte-order mark changes how text joins or displays without showing anything.\u200d \u202e \ufeff
Line and paragraph separatorsValid in a string, but some editors treat them as line breaks.\u2028 \u2029
Unpaired surrogatesHalf of a UTF-16 pair is not a character on its own (RFC 8259, section 8.2).\ud800 \udc00
Unassigned and private-use code pointsThere is no agreed character to show.\u0378 \ue000

To get the same result from Python itself, pass ensure_ascii=False to json.dumps, or --no-ensure-ascii to python -m json.tool (Python 3.9 and later).2

How to pretty print JSON in Python, JavaScript and on the command line

In Python, json.dumps takes indent for the layout, sort_keys=True to order the keys and ensure_ascii=False to keep non-ASCII text readable. From a shell, python -m json.tool reads a file and pretty prints it, with the same choices as options.2

import json data = json.loads(text) print(json.dumps(data, indent=2, sort_keys=True, ensure_ascii=False)) # or, from a shell: # python -m json.tool --indent 2 --sort-keys --no-ensure-ascii file.json

In JavaScript, the third argument of JSON.stringify sets the indentation: a number of spaces, clamped to 10, or a string of up to 10 characters.3 It has no option for sorting keys or for keeping short arrays on one line.

const pretty = JSON.stringify(JSON.parse(text), null, 2);

What beautifying never changes here

Both routes above parse the text and print it again, and printing from a parsed value can change the data: a whole number beyond 253 is rounded to the nearest 64-bit float, a trailing zero as in 10.50 is lost, an exponent as in 1E2 becomes 100, and a repeated key keeps only its last value. This page keeps the text of every number, every string (unless you tick the escape option) and every key exactly as written, and keeps duplicate keys in their original order, because it changes the whitespace and nothing else. The JSON formatter shows the numbers example in full.

Frequently asked questions

What is a JSON beautifier?

A JSON beautifier rewrites JSON with line breaks and indentation so it can be read, without changing the data. It is the same thing as a JSON pretty printer or formatter. This one also sorts keys, keeps short arrays on one line and can show \u escapes as characters.

How do I beautify JSON online?

Paste your JSON into the box and press Beautify. Choose an indent of 2, 3, 4 or 8 spaces or a tab, and tick any of the three options. The result appears below the options with its size in bytes and a count of objects, arrays, keys and values, and you can copy it or download it as a .json file.

How do I make JSON readable?

Beautify it. If the text is non-English and full of \u escapes, also tick Show \u escapes as characters. If short lists such as tags or coordinates take a line per item, tick Keep short arrays on one line. The Tree view collapses and expands each object and array when the document is large.

What is the difference between beautifying and minifying JSON?

They are opposites. Beautifying adds line breaks and indentation so people can read the structure; minifying removes every character that is not needed, giving the smallest text for the same data. Both change only whitespace, and the Minify button here also keeps numbers and keys exactly as written.

Will beautifying change my data?

No. Only whitespace changes by default: numbers, string escapes, key order and duplicate keys are kept exactly as written. The one option that changes how a string is written is Show \u escapes as characters, and it still gives a string with the same value; the result parses to the same data.

How do I turn \u escapes in JSON into readable text?

Tick Show \u escapes as characters and press Beautify. A pair such as \ud83d\ude00 becomes the emoji it encodes, and \u0645\u0631\u062d\u0628\u0627 becomes the Arabic word it spells. Control characters, invisible characters such as a zero-width joiner, non-breaking spaces and lone surrogates stay escaped so nothing hidden appears in your text.

How do I keep short arrays on one line?

Tick Keep short arrays on one line. An array that holds only strings, numbers, true, false or null stays on one line when it would be at most 60 characters long; a longer array, or one that contains an object or another array, is laid out with one item per line.

How do I sort JSON keys alphabetically?

Tick Sort keys. Every object's keys are put in order at every level of nesting, compared by their UTF-16 code units, so capitals sort before lower-case letters. Arrays keep their order and equal keys keep their original order.

Should I indent JSON with 2 spaces, 4 spaces or a tab?

It makes no difference to the data, so follow the style of the project the JSON will live in. Python's json.tool indents by 4 spaces by default, and JSON.stringify indents by whatever you pass. Pick 2 spaces for a compact result, 4 or 8 for easier scanning, or a tab to let each reader's editor choose the width.

Why does Python's json.dumps print \u escapes, and how do I stop it?

Because its ensure_ascii option is on by default, which escapes every non-ASCII character. Pass ensure_ascii=False to json.dumps, or --no-ensure-ascii to python -m json.tool, to write the characters as they are. This page can also turn existing escapes back into characters.

Can it beautify a large file?

You can open a file of up to 20 MB, and it is read by your browser and never uploaded. A document of more than 200,000 characters is beautified when you press Beautify rather than on every pause in typing, and how long a very large one takes depends on your device.

Is my JSON uploaded or stored?

No. Beautifying, minifying, fixing and opening a file all happen in your browser, and nothing you paste or open is transmitted. We count page visits and button clicks with our own analytics on our own server, and those events carry none of your data.

Sources

  1. Bray, T. (ed.), RFC 8259, The JavaScript Object Notation (JSON) Data Interchange Format (IETF, 2017): insignificant whitespace is allowed before or after any of the six structural characters, and any character in a string may be written as a \uXXXX escape (sections 2 and 7).
  2. Python Software Foundation, json — JSON encoder and decoder: the indent, sort_keys and ensure_ascii parameters of json.dumps, and the command-line options of json.tool (--indent, --sort-keys, --no-ensure-ascii).
  3. MDN Web Docs, JSON.stringify(): the space argument, a number clamped to 10 or a string truncated to 10 characters.

The layouts this page produces are checked, for every combination of options, against a second implementation written separately in Python on thousands of documents, and the rule for which escapes are shown as characters is checked against Python's Unicode tables for every code point. The checks were shown to fail when the code they guard was deliberately broken.

Related tools