Skip to the content

Contact usFree tools · No signup · Files stay on your device

Developer Tools

JSON Formatter: the complete guide to formatting and beautifying JSON

JSON Formatter: the complete guide to formatting and beautifying JSON

A JSON formatter turns a wall of text like {"id":1,"name":"Rahim"} into neatly indented lines you can read, or squeezes readable JSON back into one compact line. Our free JSON Formatter does both in your browser, and adds a collapsible tree view, optional key sorting and a few useful numbers about your data. It is made for developers, testers, students and anyone who has ever opened an API response and found one very long line.

This guide covers every control on the page, what changes and what never changes when you format, and how to handle large files and awkward numbers. If your main problem is that the JSON will not parse at all, the companion guide on finding and fixing JSON errors is the better starting point.

What JSON Formatter does

The tool reads your text as JSON, and if it is valid it prints it again in the style you choose. That is all formatting is: the same data with different whitespace.

It can:

  • Beautify JSON with 2 spaces, 4 spaces or tabs.
  • Minify JSON into a single line with no optional whitespace.
  • Sort the keys of every object from A to Z.
  • Show the data as a tree you can expand and collapse.
  • Show the input size, output size, number of keys, number of values and the deepest level.

It does not repair broken JSON by itself while formatting. If the input has a syntax error, you get an error message with the line and column instead of output. It also does not check your data against a schema, so it cannot tell you that a field is missing.

How to use JSON Formatter, step by step

  1. Open JSON Formatter.
  2. Paste your JSON into the box labelled "Paste or type JSON". You can also press Open file and pick a .json or text file, or press Sample to see how it behaves first.
  3. Under Output style, choose Beautify or Minify. With Beautify, pick the Indent: 2 spaces, 4 spaces or Tabs.
  4. Tick Sort keys A→Z if you want the keys in alphabetical order.
  5. Read the result in the right-hand panel, which is titled Formatted (or Minified). Use the View switch to change between Text and Tree.
  6. Press Copy to copy the output, or Download to save it. Beautified output is saved as data.json and minified output as data.min.json.

The page formats as you type. There is a short pause of about 0.2 seconds after your last keystroke before it re-parses, and a "Parsing…" label shows while it waits. For input above one million characters the pause is longer (0.6 seconds), so typing stays smooth.

Every option explained

Output style: Beautify or Minify

Beautify puts every key and array item on its own line, indented by nesting level. Use it for reading, debugging, code review and documentation.

Minify removes all optional whitespace. Use it when you are putting JSON in a request body, a config value or a URL parameter and every byte counts. Both styles represent exactly the same data. The Indent setting disappears when Minify is selected, because there is no indentation to choose.

Indent: 2 spaces, 4 spaces or Tabs

This only changes how deep each level is pushed to the right. Two spaces keeps deeply nested data narrow and is the most common choice for JSON. Four spaces is easier to scan on a wide screen. Tabs suits editors that show tabs at your preferred width.

Sort keys A→Z

This sorts the keys of every object, at every level, in plain alphabetical (character code) order. Arrays are not reordered. The sort affects the output panel, the tree view and Copy and Download, but your input box is left as you typed it.

Sorting is the quickest way to compare two JSON files that came from different systems. Sort both, then put the results into the Text Diff Checker, and only real differences remain instead of reordered keys.

One quirk to know: keys that are whole numbers, such as "1" or "42", are always printed first and in number order. That is how JavaScript orders object keys, and sorting cannot change it.

View: Text or Tree

Text shows the formatted or minified string. Tree shows the structure: each object or array is labelled with its type and a count such as {5 keys} or [2 items], and a ▸ or ▾ arrow opens and closes it. Strings, numbers, booleans and null each get their own colour.

The Tree toolbar has two buttons. Expand all opens as many levels as can be shown comfortably, and Collapse all folds everything back to the top level. By default the tree opens two levels. In very large arrays only the first 200 children are shown at a time, followed by a "Show … more" button, so a list of 100,000 records does not lock up the page.

What it accepts and its limits

  • Input: any valid JSON text. The top level can be an object, an array, a string, a number, true, false or null.
  • Files: Open file accepts .json and plain text files. The page does not set its own file-size limit; the practical limit is your device's memory.
  • Byte-order mark: if the text starts with an invisible BOM, which some Windows editors add, it is ignored and a note tells you so.
  • Not accepted: comments, single quotes, unquoted keys and trailing commas. These are errors in standard JSON, although Try auto-fix can remove them.
  • Large output: the text view shows the first 300,000 characters of a big result, with a note. Copy and Download always include everything.

Privacy

JSON Formatter runs entirely in your browser. Nothing you paste or open is sent to our server, which makes it suitable for private API responses, configuration files and tokens. You can confirm this on a computer by opening the browser's developer tools, going to the Network tab and watching that formatting causes no requests.

What formatting changes, and what it does not

Formatting parses your JSON and then prints it again, so the tool shows the data as JSON itself understands it. Three small effects follow from that.

In your input In the formatted output
450.50 450.5 (trailing zero dropped)
"\u09ac\u09be\u0982\u09b2\u09be" "বাংলা" (escape written as the real characters)
Two copies of the same key in one object Only the last one is kept

The values mean exactly the same, but if you need byte-for-byte text, do not replace your original with the formatted copy.

A worked example

Suppose an order API returns this on one line:

{"orderId":"BD-20418","customer":{"name":"Rahim Uddin","phone":"01712345678"},"items":[{"sku":"A1","qty":2,"price":450.50},{"sku":"B7","qty":1,"price":1200}],"total":2101,"paid":false}

Paste it, leave Beautify and 2 spaces selected, and the Formatted panel shows:

{
  "orderId": "BD-20418",
  "customer": {
    "name": "Rahim Uddin",
    "phone": "01712345678"
  },
  "items": [
    {
      "sku": "A1",
      "qty": 2,
      "price": 450.5
    },
    {
      "sku": "B7",
      "qty": 1,
      "price": 1200
    }
  ],
  "total": 2101,
  "paid": false
}

The green note reads "Valid JSON ✓ — top level is an object with 5 keys", and the numbers under the panels show 13 keys, 16 values and a maximum depth of 3. Note that the phone number stays a string. That matters: written as a plain number, 01712345678 would be invalid JSON, because numbers cannot start with a zero.

Now tick Sort keys A→Z and the top level becomes customer, items, orderId, paid, total.

Tips to work faster

  • Use Sample to see what a clean result looks like, and Broken sample to see how errors are reported.
  • Switch to Tree when you only want to find one value in a large response. Collapse all, then open just the branch you need.
  • Read the stats row: "Max depth" tells you how deeply nested the data is, and "Keys" and "Values (nodes)" give a quick feel for its size.
  • Minify before pasting JSON into a form field or a one-line config, then beautify again when you need to edit.
  • For a response copied from the browser's Network tab, the step-by-step is in how to read a minified JSON API response quickly.

Common problems and how to fix them

"Invalid JSON — line 3, column 12"

The output stays empty, and a red message gives the line, column and a plain-English reason, with a snippet and a caret under the spot. The caret marks where the parser noticed the problem, which is sometimes just after the real mistake. For example, a missing comma is reported at the start of the next item. The validation guide explains each message: JSON Validator: the complete guide.

"Try auto-fix found nothing"

Auto-fix handles comments, single quotes, unquoted keys, trailing commas and True/False/None. It cannot add a missing comma or close a missing bracket, because it cannot know what you meant. The message then says to check the error position and edit by hand.

A long number changed after formatting

If a whole number is larger than 9,007,199,254,740,991, JavaScript cannot hold it exactly, so the output rounds it. The page shows a yellow warning when it finds such a number. Long IDs such as 19-digit order or transaction numbers should be sent as strings.

The output is cut off

That is the 300,000-character preview limit. Use Copy or Download, which include the whole result.

The tree says it expanded only a few levels

For large documents, Expand all stops at a depth that keeps the page responsive and shows a hint. Click the ▸ arrows to open deeper branches yourself.

  • JSON Validator: the same engine with the verdict at the top, for checking and fixing errors.
  • JSON to CSV: turn an array of records into a table for Excel.
  • Text Diff Checker: compare two formatted, key-sorted documents line by line.
  • Developer Tools: the rest of our developer utilities.

Quick checklist

  • Choose Beautify to read and Minify to send.
  • Pick one indent and use it everywhere in the project.
  • Sort keys before comparing two files.
  • Keep long IDs and phone numbers as strings.
  • Keep your original; formatting rewrites numbers and escapes.

Frequently asked questions

Does formatting change my JSON data?
Only the layout changes: spaces, tabs and line breaks. The tool reads your JSON and prints it again, so numbers are written in their shortest form (450.50 becomes 450.5) and \u escapes become real characters, but every key and value stays the same.
Which indent should I choose?
Use 2 spaces for most code and API work, 4 spaces if your team's style guide asks for it, and Tabs if your editor is set up for tabs. The data is identical in all three.
Why is there no formatted output when my JSON is wrong?
The tool only prints JSON it can parse. When there is an error, the output panel says to fix it first and a red message shows the line, column and reason, with a Try auto-fix button for common mistakes.
What does Sort keys A→Z do to arrays?
Nothing. Only the keys inside objects are sorted, at every level. Items in an array keep their order, because for arrays the order is part of the data.
Why does the page show only part of a very large result?
Showing several megabytes inside a text box would freeze the tab. The text view shows the first 300,000 characters, and the Copy and Download buttons still give you the complete result.
Found this useful? Share it

Tools in this guide

Main tool

JSON Formatter

Paste messy or minified JSON to get clean, indented output instantly — or minify it for production.

Open tool

JSON Validator

Check whether your JSON is valid and get the exact line, column and reason for any error.

Open tool

JSON to CSV

Turn JSON arrays into a CSV you can open in Excel or Google Sheets.

Open tool

Text Diff Checker

Paste or open two versions of a text and see exactly what changed: added lines in green, removed lines in red.

Open tool

Back to all guides & blog