Skip to content

JSON Formatter and Validator

Check whether JSON is valid, then beautify, minify or sort it. When it is not valid, the parser's message tells you where it stopped, and the table below tells you why.

Runs in your browserFree, no sign-upLast reviewed

Settings

Results update automatically as you type.

Valid JSON. This JSON parses successfully.

Formatted JSON

{
  "name": "Ada",
  "languages": [
    "JS",
    "TS"
  ],
  "active": true
}

Structure

Keys
3
Arrays
1
Max depth
3
Size
78 chars
Saved by minifying
0 chars

Quick answers

How do I check if my JSON is valid?
Paste it into the JSON box. Valid input shows the note This JSON parses successfully. Invalid input shows Invalid JSON followed by the parser's reason and, for most errors, the position, line and column where it stopped reading.
Why is my JSON invalid?
The usual causes are a trailing comma after the last item, single quotes instead of double quotes, keys without quotes, comments, a missing comma between items, or values JSON does not have, such as undefined, NaN, None or True with a capital T.
What does Unexpected token mean in JSON?
The parser met a character that cannot appear at that point. Unexpected token '<' almost always means the text is an HTML page, such as a server error page, not JSON. Unexpected token 'u' or 'N' points to undefined, NaN or None used as a value.
How do I pretty print JSON?
Paste the one-line JSON and leave Output on Beautify with 2 spaces, or pick 4 spaces or tabs. Each key and array item is placed on its own line, indented one step per level of nesting.
Does formatting JSON change the data?
Whitespace changes never alter the data. Because this tool parses and rewrites the document, three details can change: number spelling (1.0 becomes 1, 1e3 becomes 1000), duplicate keys (only the last survives) and integers too large for a double.
Is my JSON sent to a server?
No. Parsing and formatting use the JSON functions built into your browser. Nothing you paste is transmitted, so API responses containing customer records or internal identifiers stay on your machine.

About JSON Formatter & Validator

Paste JSON and the tool parses it with your browser's own JSON engine. Valid input gets a confirmation note and comes back indented with 2 spaces, 4 spaces or tabs, or minified onto one line, with an option to sort every object's keys alphabetically. A Structure panel counts keys and arrays and reports the maximum nesting depth, the output size and how many characters minifying saves. Invalid input returns the parser's error message, which in Chrome and Edge gives, for most errors, the position, line and column where parsing failed. Because the document is re-serialised from parsed data, a few things are normalised: 1.0 becomes 1, a duplicate key keeps only its last value, and integers beyond 9,007,199,254,740,991 can lose precision.

JSON parse error messages and how to fix them

Messages are shown as Chrome and Edge word them, each produced by running the broken input through this tool. Firefox and Safari report the same problems in different words.

Broken inputError messageCause and fix
{"a":1,}Expected double-quoted property name in JSON at position 7 (line 1 column 8)Trailing comma in an object. Delete the comma before the closing brace.
[1,2,3,]Unexpected token ']', "[1,2,3,]" is not valid JSONTrailing comma in an array. Delete the last comma.
{'a':1} or {a:1}Expected property name or '}' in JSON at position 1 (line 1 column 2)Single-quoted or unquoted key. Keys must be in double quotes.
{"a":1 "b":2}Expected ',' or '}' after property value in JSON at position 7 (line 1 column 8)Missing comma between two properties. The same message appears for a // comment, a semicolon used as a separator, or a missing closing brace.
["a","b"Expected ',' or ']' after array element in JSON at position 8 (line 1 column 9)The array is never closed, or a comma is missing between items.
{"a"=1}Expected ':' after property name in JSON at position 4 (line 1 column 5)An equals sign or nothing where the colon should be.
{"a":undefined}Unexpected token 'u', "{"a":undefined}" is not valid JSONundefined is not a JSON value. Use null or remove the key.
{"a":NaN} or {"a":None}Unexpected token 'N', ... is not valid JSONNaN, Infinity and Python's None do not exist in JSON. Use null.
{"a":True}Unexpected token 'T', "{"a":True}" is not valid JSONLiterals are lowercase only: true, false and null.
{"a":01}Unexpected number in JSON at position 6 (line 1 column 7)Leading zeros are not allowed. Write 1, or quote the value if it is a code such as "01".
{"a":.5} or {"a":+1}Unexpected token '.', ... or Unexpected token '+', ...A number needs a digit before the decimal point and cannot start with a plus sign. Write 0.5 and 1.
A string containing a real line break or tabBad control character in string literal in JSON at position ...Write line breaks as \n and tabs as \t inside strings.
{"a":"unterminated}Unterminated string in JSON at position 19 (line 1 column 20)A closing double quote is missing.
A string containing \xBad escaped character in JSON at position ...Only \" \\ \/ \b \f \n \r \t and \u followed by four hex digits are valid escapes.
{"a":1}{"b":2}Unexpected non-whitespace character after JSON at position 7 (line 1 column 8)Two documents in one paste, as in JSON Lines logs. Format one line at a time or wrap them in an array.
<html><body>502</body></html>Unexpected token '<', "<html><bod"... is not valid JSONThe response is an HTML page, not JSON. Check the URL and the status code of the request.

Position counts characters from 0; line and column count from 1. The parser stops at the first problem, so fix it and look again for the next.

Formatting, minifying and sorting examples

Results and Structure figures are taken from the tool.

Beautify the default sample

{"name":"Ada","languages":["JS","TS"],"active":true} with Beautify, 2 spaces

8 lines, 78 characters. Structure: Keys 3, Arrays 1, Max depth 3. With 4 spaces the same document is 94 characters.

Minify a nested API response

An object with a users array of two objects and a meta object, indented with 4 spaces (266 characters), Output set to Minify

{"users":[{"id":1,"tags":["a","b"]},{"id":2,"tags":[]}],"meta":{"page":1,"total":2}} Size 84 chars, Saved by minifying 182 chars. Keys 8, Arrays 3, Max depth 5.

The same document is 188 characters with 2-space indentation and 149 with tabs.

Sort keys at every level

{"zip":"10001","city":"New York","address":{"street":"5th Ave","number":350}} with Sort keys alphabetically ticked

Top-level order becomes address, city, zip, and inside address the order becomes number, street.

Arrays keep their original order. Only object keys are sorted.

A 64-bit identifier

{"id":9007199254740993}

{ "id": 9007199254740992 }

The last digit changed. Integers above 9,007,199,254,740,991 are not all representable as a JavaScript number, so send large IDs as strings.

Number spellings and a duplicate key

{"price":1.0,"qty":1e3,"rate":0.10} and, separately, {"a":1,"a":2}, both minified

{"price":1,"qty":1000,"rate":0.1} and {"a":2}

JSON syntax rules compared with a JavaScript object literal

Most invalid JSON is valid JavaScript. These are the differences that matter.

FeatureJSONJavaScript object literal
Key quotingDouble quotes requiredOptional for simple names
String quotesDouble quotes onlySingle, double or backticks
Trailing commaNot allowedAllowed
CommentsNot allowedAllowed
undefined, NaN, InfinityNot allowedAllowed
true, false, nullLowercase onlyLowercase only
Leading zero or plus sign on numbersNot allowedPlus sign allowed
Hexadecimal numbers such as 0x1FNot allowedAllowed
Top-level valueAny value: object, array, string, number, true, false or nullNot applicable

Files such as tsconfig.json and VS Code settings use JSON with Comments, a separate dialect. A strict parser, including this one, rejects their comments and trailing commas.

What the Structure panel counts

  • Keys is the total number of object properties at every level. The users and meta example has 8: users, meta, two id, two tags, page and total.
  • Arrays is the number of arrays anywhere in the document, including empty ones.
  • Max depth counts the root value as level 1 and adds one for each nested object or array. A flat object of plain values has depth 2.
  • Size is the length in characters of the output currently shown, so it changes with the indent you pick.
  • Saved by minifying is the length of what you pasted minus the length of the minified form. It is 0 when the input is already on one line with no spaces.

How Sort keys alphabetically orders keys

Sorting is applied to every object in the document, however deeply nested, and compares keys the way your browser's locale-aware text comparison does. Lowercase comes before uppercase for the same letter, so b is placed before B, and a key starting with an underscore comes before letters.

Keys that are whole numbers behave differently, and this is true whether or not you tick the box. JavaScript always lists integer-like keys first, in ascending numeric order, so {"b":1,"2":5,"a":3,"10":4} is output as 2, 10, b, a even with sorting off. With sorting on it becomes 2, 10, a, b.

Reordering keys does not change the meaning of a JSON document, because the specification treats an object as an unordered collection. That makes sorting a safe way to normalise two documents before comparing them: with the same indent and sorted keys, a text diff shows only the values that differ.

How to get your result

  1. 1

    Paste your document into the JSON box, replacing the sample object.

  2. 2

    Choose an Output: Beautify with 2 spaces, 4 spaces or tabs, or Minify.

  3. 3

    Tick Sort keys alphabetically if you want every object's keys in a fixed order, for example before comparing two documents.

  4. 4

    If the input is valid, a Valid JSON note appears. Copy the Formatted JSON or Minified JSON, or download it as data.json.

  5. 5

    If you see Invalid JSON, read the message for the reason and, where given, the position, line and column, then fix that spot.

  6. 6

    Check the Structure panel for Keys, Arrays, Max depth, Size and Saved by minifying.

Frequently asked questions

What is the difference between a JSON formatter and a JSON validator?
A validator answers one question: does this text follow the JSON grammar? A formatter rewrites valid JSON with consistent indentation. This tool does both in one step, because text has to be parsed successfully before it can be re-indented.
Can it fix invalid JSON automatically?
No. It reports the first error and where it is, but it does not repair anything. Remove trailing commas, replace single quotes with double quotes and delete comments by hand, using the error table above to match the message to the cause.
Does it validate against a JSON Schema?
No. It checks syntax only: whether the text is well-formed JSON. It does not check that required fields are present or that values have the right type, which is what JSON Schema validation does.
Should I use 2 spaces, 4 spaces or tabs?
Use whatever the project already uses. Two spaces is the most common choice for JSON and keeps deeply nested data narrow. For the nested example on this page the output is 188 characters with 2 spaces, 266 with 4 spaces and 149 with tabs.
When should I minify JSON?
Minify payloads that are sent over a network or stored in bulk, where whitespace is wasted bytes. Keep configuration files and anything in version control formatted, because a diff of a one-line file shows the whole line as changed.
Why did escaped characters in my strings change?
Escapes are decoded on parsing and written back in the shortest valid form. \u00e9 comes back as é and \/ comes back as a plain slash. The strings are identical in value; only their spelling in the file differs.
Can I format JSON Lines or several objects at once?
Not in one paste. A file with one JSON object per line is not a single JSON document, so the parser stops after the first object with Unexpected non-whitespace character after JSON. Paste one line at a time, or put the objects in an array.
Is a single number or string valid JSON?
Yes. The current specification, RFC 8259, allows any JSON value at the top level, so 42, "hello", true and null are each a complete document. Paste one and the tool reports it as valid with a depth of 1.

Looking for something else? Browse all developer tools or see every tool.