← All blog posts

JSON Formatter — The Complete Guide

WhiteUI · A plain-English guide to the JSON Formatter

A block of JSON has a surprising number of details: two modes, three counts in the result panel, two ways to take the result away, and error messages that name exact positions. This guide covers every part of the JSON Formatter, so you never have to guess what a setting does.

At a glance

Compact: 90 of 120 characters90 chars compact30 chars of indentSame data in both modes
Compact output is 90 characters, which is 75 percent of the 120-character Pretty output, holding the same data.

The two modes

Pretty spreads the JSON across lines with two spaces of indent per level, so the sample becomes 9 lines and 120 characters, and you can read the structure at a glance. Compact squeezes it onto one line with no extra spaces, so the same sample becomes 90 characters, and it fits where space is tight. Behind the buttons, Pretty is JSON.stringify(value, null, 2) and Compact is JSON.stringify(value). Both preserve the keys, the values and their order.

The sample, line by line

The Pretty output of the sample has 9 lines, and each one has a job. Line 1 is the opening brace, line 2 is the name key, line 3 opens the tools list, lines 4 and 5 are the two tool names four spaces in, line 6 closes the list, lines 7 and 8 are the free and tools_count keys, and line 9 is the closing brace.

The counts in the result panel

Three lines under the big number describe the result. The big line is the length of the formatted text: “120 characters” in Pretty, “90 characters” in Compact. The first small line names the mode and the structure: “Valid JSON · 4 top-level keys · Mode: Pretty”. The second small line compares the lengths: “Original: 98 characters · Formatted: 120 characters”. If the input is invalid, the big line reads “Invalid JSON” instead, and the first small line shows the parser’s error.

Copy and download

Two buttons sit under the output box. “Copy JSON” puts the formatted text on the clipboard, so you can paste it into a code editor, a document, or a message. “Download .json” saves it as a file called formatted.json, which you can open in any editor or send to someone else. Nothing is uploaded in either case: both happen in your browser.

Errors, and what they mean

Four errors cover almost every invalid input. {oops} fails at position 1, because the keys are not in double quotes. {"a": 1,} fails at position 8, because of the comma before the closing brace. {"name": "x", "age": } fails with “Unexpected token ‘}’”, because a value is missing after the colon. A trailing comma inside a list, such as [78, 85, 92,], fails at the closing bracket with “Unexpected token ‘]’”. In every case the error names a position: count characters from the start, with the first character at position 0, and the fault is at or just before that spot.

Three more worked examples

A weather report, {"city": "Mumbai", "temp_c": 31, "rain": false}, is 47 characters in, 55 characters and 5 lines in Pretty, and 42 characters in Compact. A settings object, {"theme": "dark", "font_size": 14, "notifications": true}, is 57 characters in, 65 characters and 5 lines in Pretty, and 52 characters in Compact. A deeply nested object, {"a": {"b": {"c": 1}}}, is 22 characters in, 46 characters and 7 lines in Pretty, and 19 characters in Compact, with the value 1 sitting six spaces in at the third level. Deep inputs grow the most in Pretty, because every level adds two spaces to every line below it.

The common mistake

People treat the character count as a measure of how much data they have, and worry when Pretty shows 120 characters for the same data Compact shows as 90. The count measures the text, not the data: the same four keys and the same values take 98 characters as pasted, 120 spread out, and 90 squeezed, and all three are the same information. Judge the result by the key count, 4 top-level keys, and by the values, not by how long the text is.

Frequently asked questions

What are the two modes of the JSON Formatter?

Pretty spreads the JSON across lines with 2 spaces of indent per level, so the sample is 120 characters; Compact puts it on one line, so the same sample is 90 characters. The data is identical in both.

How many lines is the formatted sample?

9 lines in Pretty mode: the opening brace, 4 key lines, 2 list items, the closing bracket and the closing brace.

What do the counts in the result panel mean?

The big line is the formatted length, the first small line names the mode and the top-level key count, and the second compares the original and formatted lengths.

How do I save the formatted JSON?

Press Copy JSON to put it on the clipboard, or Download .json to save it as formatted.json.

What are the most common JSON errors?

Missing double quotes, failing at position 1; a trailing comma, failing at position 8 in {"a": 1,}; and a missing value, failing with “Unexpected token ‘}’”.

More guides on the JSON Formatter

Try it yourself

Try the JSON Formatter — free, in your browser.

Open the JSON Formatter