Mr. Tools

How to

How to use JSON Formatter

Paste JSON and it is formatted on the right right away. If something is wrong, the line and column and the reason appear above the input box, and that line is marked. What you enter is not sent anywhere and stays only on this device.

JSON Formatter thumbnailJSON Formatter thumbnail
Steps
4 steps
Guide
With screenshots
Content
Notes and FAQ

Use Cases

When to use it

  • Make an API response easy to read and check what is in it
  • Find out what is wrong with JSON that will not load
  • Tidy a JSON config file before passing it to someone
  • Put keys in the same order before comparing two JSON files
  • Minify JSON to one line to make it smaller
  • Understand the structure of deeply nested JSON

Capabilities

What this tool can do

  • Format pasted JSON right away (Indent space 2, Indent space 4, Indent tab)
  • Minify JSON to one line by removing spaces and line breaks
  • Show where a mistake is by line and column, with the reason
  • Sort keys alphabetically (the order inside arrays stays the same)
  • Read deeply nested JSON as a tree
  • Copy the result or save it as formatted.json

Steps

Steps

The order of operations and checkpoints are listed so you can proceed while looking at the screen.

STEP 1

Paste your JSON

Paste JSON into the "Input" box on the left. While the box is empty, you can also press "Paste" in the bar at the bottom. There is no convert button: the formatted JSON appears in "Result" on the right right away.

The input box and the result box outlined in red

Checkpoints

  • Formatted JSON appeared in "Result" on the right
  • No red band is showing above the input box

Where to look on screen

01
Paste and sample

"Paste" puts in the JSON you have copied as it is. To try the tool, press "Insert sample" to put in sample JSON.

"Paste" and "Insert sample" in the bottom bar outlined in red

STEP 2

Fix any errors

If the JSON has a mistake, a red band appears above the input box and shows where and why, such as "Line 3, column 16: There is an extra comma after the last item". That line gets a red mark, and the wrong character gets a darker mark. Fix it as the band says, and the band disappears and the result appears.

The error band and the marked line outlined in red

Checkpoints

  • The red band is gone
  • Formatted JSON appeared in "Result" on the right

Where to look on screen

01
Error band

Shows the line and column of the mistake and what is wrong. How to fix each kind of mistake is listed under "Common mistakes and how to fix them" below.

The error band above the input box outlined in red

STEP 3

Choose a format

Under "Format" at the top, choose an indent width or minify. For reading, Indent space 2 or 4 works well. To pass the JSON to another program or make it smaller, Minify is the better fit. To put the keys in order, turn on "Sort keys".

"Format" and "Sort keys" outlined in red

Checkpoints

  • The format matches what the receiver expects
  • The shape of the result changed

Where to look on screen

01
Format

Choose from "Indent space 2", "Indent space 4", "Indent tab", and "Minify". Minify removes spaces and line breaks and puts everything on one line.

The format choice outlined in red
02
Sort keys

When on, the keys are sorted alphabetically. Sorting two JSON files before comparing them makes the differences easier to spot.

The "Sort keys" switch outlined in red

STEP 4

Check the result and take it with you

Check the formatted JSON in "Result" on the right, then take it with "Copy" or "Save". For deeply nested JSON, switch to "Tree" to read it while folding parts away.

The result box outlined in red

Checkpoints

  • The result is not cut off
  • It can be read where you took it

Where to look on screen

01
Text and tree

In "Tree", you can open and close nested parts as you read. The first two levels are open at the start.

The tree view of the result outlined in red
02
Copy and save

"Copy" copies the result, and "Save" saves it as formatted.json.

"Copy" and "Save" in the result box outlined in red

Common mistakes and how to fix them

We entered common mistakes and checked the message shown in the band. None of these can be read by the browser's own JSON parser either.

Band message and fix for each mistake
MistakeJSON enteredBand messageFix
Comma after the last item{"name": "Item A", "price": 1200,}Line 1, column 33: There is an extra comma after the last itemRemove the last comma
Comma at the end of an array{"tags": ["new", "sale",]}Line 1, column 24: There is an extra comma after the last itemRemove the comma before ]
Missing comma{"name": "Item A" "price": 1200}Line 1, column 19: A comma (,) is missingAdd , after "Item A"
Missing colon{"name" "Item A"}Line 1, column 9: A colon (:) is missing after the keyAdd : after "name"
Text in single quotes{'name': 'Item A'}Line 1, column 2: Use " instead of ' for quotesChange every ' to "
Key without quotes{name: "Item A"}Line 1, column 2: Wrap the key in quotes (")Change name to "name"
Unclosed string{"name": "Item A}Line 1, column 10: The closing quote (") of a string is missingAdd " after Item A
Comment{"price": 1200 // tax included}Line 1, column 16: Comments are not allowed. Remove the // or /* */ partRemove everything from // to the end of the line
Missing closing bracket{"tags": ["new", "sale"]Line 1, column 25: The JSON ends too early. Check the closing bracketsAdd } at the end
Extra characters after the JSON{"price": 1200} }Line 1, column 17: There are extra characters after the JSONRemove the last }
A value JSON does not have{"price": undefined}Line 1, column 11: This character is not allowed hereUse null or a number

The column is the number of characters counted from the start of the line. Full-width characters, such as Chinese or Japanese, also count as one character. When there are several mistakes, they are shown one at a time from the front. Fix one, and the next one appears in the band.

How does the format change the number of characters?

Using the same product data JSON (name, price, tags, stock), we compared the output characters shown under the result box.

Characters by format
FormatOutput characters
Indent space 2127
Indent space 4155
Indent tab113
Minify82

Minify makes it about 30% shorter than space 2. Use space 2 or 4 for reading, Minify to make the data smaller, and tabs when the receiver asks for them.

What changes when you sort keys?

With the same product data, turning on "Sort keys" put the keys in alphabetical order. Keys inside nested objects are sorted too.

Key order (shown minified)
StateResult
Before sorting{"name":"Item A","price":1200,"tags":["new","sale"],"stock":{"tokyo":3,"osaka":0}}
After sorting{"name":"Item A","price":1200,"stock":{"osaka":0,"tokyo":3},"tags":["new","sale"]}

stock and tags switched places, and so did tokyo and osaka inside stock. The order of "new" and "sale" inside tags did not change, because the order of an array can carry meaning in the data.

Tips for reading long JSON

  • Press Ctrl+F (⌘+F on Mac) in the input box to find a key or value. You can also replace what you find with other text
  • For minified one-line JSON, turn on "Wrap lines" in "View options" at the top right of the box to read it without scrolling sideways
  • If you clear the box by mistake, press "Undo" in the notice that appears to bring it back

Notes

Notes

Important points are grouped with reasons so you can make decisions before using the tool.

Syntax

Comments and trailing commas are not allowed

They may work in JavaScript, but they are errors in JSON. Remove them and the JSON can be formatted.

Sorting

Only keys are sorted

The order inside arrays does not change, so data whose order matters stays as it is.

Saving

Your JSON stays on this device

You can pick up where you left off after reopening the page. On a shared device, press "Clear" when you are done.

FAQ

Questions about JSON Formatter

Questions that make decisions easier before use are summarized first.

Can I change the indent width?

Yes. Under "Format", choose from Indent space 2, Indent space 4, Indent tab and Minify.

How are errors shown?

A message such as "Line 3, column 16: There is an extra comma after the last item" appears above the input box, showing where and why. That line is marked.

Can it handle JSON with comments (JSON5 or JSONC)?

No. Only standard JSON works. If there is a comment, you see "Comments are not allowed", so remove that part.

Does sorting keys change the order of arrays?

No. Only object keys are sorted. The order inside arrays stays as it is.

Is the JSON I enter sent anywhere?

No. Formatting happens in your browser. What you enter stays only in this device's browser, so you can pick up where you left off after reopening the page.

Can it handle large JSON?

Yes, within what your browser can handle. Very large JSON may take longer to format or make the page slow to respond.

Can it format anything other than JSON?

This tool is for JSON only. To format HTML and CSS, use HTML Formatter and CSS Formatter.

Next guides

Related guides

Related guides are listed next so you can continue without getting lost.