pttooz

JSON Formatter

Validate, beautify or minify JSON live — with error pinpointing, a tree view and structure charts.

Live

How JSON Formatter calculator works?

The JSON Formatter works in 5 steps: it parses the input, pinpoints syntax errors, re-prints the data with your indent, measures the structure and compares sizes. JSON (JavaScript Object Notation) is the text data format defined in RFC 8259.

  1. 1

    Parse the input

    The browser JSON parser reads the input 120 milliseconds (ms) after you stop typing.

  2. 2

    Pinpoint errors

    A strict scanner walks the text character by character and reports the line and column of the first invalid character, with a 5-line snippet and a caret.

  3. 3

    Re-print the data

    JSON.stringify writes the data back with 2 spaces, 4 spaces, tabs or no whitespace (minified). “Sort keys” orders object keys A–Z at every level.

  4. 4

    Measure the structure

    A tree walk counts keys, values of 6 types (object, array, string, number, boolean, null) and nodes at each nesting depth.

  5. 5

    Compare sizes

    The Blob API measures 3 versions in UTF-8 bytes: your input, the minified output and the 2-space output.

JSON Formatter formula

The JSON Formatter uses 4 measurements: total values, maximum depth, UTF-8 byte size and minification saving. The examples use the built-in sample file.

Total values

V = objects + arrays + strings + numbers + booleans + nulls
V
Every node in the document, root included
Keys
Counted separately: names inside objects
Sample file values38
Sample file keys25
Result38 values · 25 keys

Maximum depth

D = max(level of every node), root = 0
D
Deepest nesting level
root → toolslevel 1
tools → item 3level 2
item 3 → defaultslevel 3
defaults → amountlevel 4
ResultD = 4

UTF-8 byte size

Bytes = Σ bytes per character
1 byte
ASCII, U+0000–U+007F (a, 7, {)
2 bytes
U+0080–U+07FF (é, ß, Arabic, Hebrew)
3 bytes
U+0800–U+FFFF (most Chinese, Japanese, Korean, Hindi)
4 bytes
U+10000 and above (emoji)
"café""c a f" = 3 bytes + é = 2 bytes
+ 2 quotes7 bytes
Result7 bytes

Minification saving

S = (pretty − minified) ÷ pretty × 100
pretty
Size with 2-space indent
minified
Size with no whitespace
748 − 427321 bytes
321 ÷ 748 × 10042.9%
Result42.9% smaller

JSON Formatter conversion chart

The JSON Formatter conversion chart maps the 6 JSON data types to JavaScript, Python and PHP types, and lists the 9 escape sequences JSON strings accept.

JSON typeExampleJavaScriptPythonPHP
object{ "a": 1 }Objectdictarray / stdClass
array[1, 2]Arraylistarray
string"text"Stringstrstring
number42, 3.14, 1e6Numberint / floatint / float
booleantrue, falseBooleanbool (True / False)bool
nullnullnullNonenull
JSON string escape sequences
EscapeMeaningExample
\"Double quote"say \"hi\""
\\Backslash"C:\\Users"
\/Forward slash (optional)"a\/b"
\bBackspaceU+0008
\fForm feedU+000C
\nLine feed (new line)"line 1\nline 2"
\rCarriage returnU+000D
\tTab"a\tb"
\uXXXXAny character by code point"\u00e9" → é

JSON Formatter FAQ

Is my JSON uploaded to a server?

No, the JSON Formatter parses and formats JSON inside your browser and uploads nothing. API keys, tokens and customer records in the input stay on your device.

Why is my JSON invalid?

JSON is invalid when the text breaks a syntax rule of RFC 8259. There are 6 frequent errors: trailing commas, single-quoted strings, unquoted keys, comments, missing commas between items, and values such as NaN, Infinity or undefined. The error panel shows the line and column of the first error.

Does JSON allow comments?

No, standard JSON does not allow comments. RFC 8259 defines no comment syntax, and // or /* */ cause a parse error. JSONC and JSON5 are JSON variants that accept comments.

What is the difference between formatting and minifying JSON?

Formatting adds line breaks and indentation for reading, and minifying removes all whitespace for transfer. The data stays identical. The sample file is 748 bytes formatted with 2 spaces and 427 bytes minified, a 42.9% saving.

Does sorting keys change my data?

No, sorting keys does not change the data. RFC 8259 defines an object as an unordered collection of name/value pairs. Arrays keep their original order.

Does the JSON Formatter keep large numbers exact?

No, numbers above 9,007,199,254,740,991 (253 − 1) lose precision. JavaScript stores every JSON number as a 64-bit float. Store large IDs as strings, such as "id": "9007199254740993".

How large a document does the tree view show?

The tree view shows the first 1,500 nodes of a document, and the Code view shows the full formatted output at any size.