JSON Validator

Updated . The rules cited are from RFC 8259, the Python documentation and MDN, listed at the bottom.

Paste JSON to check it against the JSON standard, RFC 8259. Valid JSON is confirmed with what is in it: the kind of document, how many keys, how deep and how big. Invalid JSON gets the exact line and column, the line itself with a caret under the problem, a plain-English hint and a button that jumps to the spot. Nothing you paste or open is uploaded.

Quick answer. Paste your JSON in the box and read the verdict under it; it updates as you type. Valid JSON means the syntax follows RFC 8259. Invalid JSON shows where parsing stops and why: press Go to the error to select that character, or Fix common mistakes to repair comments, trailing commas, single quotes, unquoted keys and Python's True and None. The example in the box has a trailing comma, the most common error, and stops at line 4, column 31.

JSON validator

Invalid JSONLine 4, column 31

Trailing comma: JSON does not allow a comma before a closing bracket or brace. Remove the comma before this character.

  "skills": ["maths", "notes",],
                              ^

How to validate JSON

  1. Paste or open your JSON. Paste the text into the box, or press Open a file to read a .json or .txt file from your device (up to 20 MB). The file is read by your browser and never uploaded.
  2. Read the verdict. It updates a moment after you stop typing. Valid JSON is followed by what the document is, its size and any warnings; Invalid JSON is followed by the line and column where parsing stopped.
  3. Go to the error. Press Go to the error to select the character where parsing stopped. The hint says what the parser expected there, and the caret under the printed line points at the same character.
  4. Fix it and check again. Correct the spot by hand, or press Fix common mistakes to repair comments, trailing commas, single or curly quotes, unquoted keys and Python's True, False and None. A missing comma or an unclosed bracket is left for you, because guessing would change your data.

A parser stops at the first error, so fixing one can reveal the next. Repeat until the verdict turns to Valid JSON.

What counts as valid JSON

Validity is decided by a short grammar in RFC 8259. These are the parts of it that decide most verdicts, with the mistake each one catches:1

The rules of RFC 8259 that decide whether text is valid JSON
PartThe ruleA mistake it catches
WhitespaceOnly a space, a tab, a line feed and a carriage return may sit between tokens.A non-breaking space copied from a web page
ValuesA value is an object, an array, a number, a string, or one of the literal names true, false and null, in lower case and nothing else.True, None, undefined
The whole textA JSON text is one value. It does not have to be an object or an array: 42 and "text" are valid.Two documents in a row, or text after the end
ObjectsMembers are "name": value pairs, each name a string, separated by single commas, with no comma after the last one.{a: 1}, {"a": 1,}
NumbersAn optional minus, an integer without leading zeros, an optional fraction and an optional exponent. Infinity and NaN are not permitted.07, +1, .5, 0x1F, NaN
StringsIn double quotes. A quotation mark, a backslash and the control characters U+0000 to U+001F must be escaped, and the only escapes are \" \\ \/ \b \f \n \r \t and \uXXXX.'a', a raw line break inside a string, "C:\Users"
EncodingText exchanged between systems must be UTF-8, and a byte-order mark must not be added at the start.An invisible U+FEFF before the first brace

Syntax is all this checks. Whether the data has the fields and types you expect is a schema check, a separate job that needs a schema as well as the data, and it is not offered here. A parser is allowed to accept more than the grammar (RFC 8259, section 9), which is why a JSON library can accept text this page rejects.

Common JSON errors, where the validator stops, and what to do

The table is written by this page's own validator. The third column is where it stops, the fourth is the hint it shows, the fifth says whether Fix common mistakes repairs it, and the button loads the broken JSON into the box so you can watch it happen.

14 mistakes, where this validator stops on each, and whether Fix common mistakes repairs it
MistakeThe JSONWhere it stopsWhat it meansFix button
Trailing comma{"a": 1, "b": 2,}line 1, column 17Trailing comma: JSON does not allow a comma before a closing bracket or brace. Remove the comma before this character.Yes: {"a": 1, "b": 2}
Single quotes{'a': 1}line 1, column 2Strings and keys must use straight double quotes, not single quotes.Yes: {"a": 1}
Unquoted key{a: 1}line 1, column 2Object keys must be in double quotes.Yes: {"a": 1}
Comment{"a": 1 // note\n}line 1, column 9JSON does not allow comments.Yes: {"a": 1 \n}
Python values{"ok": True, "v": None}line 1, column 8The words true, false and null must be lowercase in JSON. (True is a Python spelling.)Yes: {"ok": true, "v": null}
Missing comma{"a": 1 "b": 2}line 1, column 9Two items are not separated by a comma.No, fix by hand
Missing colon{"a" 1}line 1, column 6A colon is missing between this key and its value. Write "key": value.No, fix by hand
Leading zero[07]line 1, column 3Numbers cannot have leading zeros. Write 7, not 07.No, fix by hand
Unclosed bracket{"a": [1, 2line 1, column 12The text ends before the JSON is complete. A bracket, brace or quote is probably not closed.No, fix by hand
Mismatched bracket{"a": [1, 2}line 1, column 12This closing brace does not match: the innermost open bracket is [, an array, which closes with ].No, fix by hand
NaN{"n": NaN}line 1, column 7NaN is not a JSON value. Use null or a string instead.No, fix by hand
Backslash in a Windows path{"p": "C:\Users\ada"}line 1, column 10A backslash starts an escape in JSON, and \U is not a valid escape. The valid ones are \" \\ \/ \b \f \n \r \t and \uXXXX. To write a backslash, use two: a Windows path "C:\Users" is written "C:\\Users".No, fix by hand
Raw line break in a string{"a": "line one\nline two"}line 1, column 16A raw line break or tab inside a string is not allowed. Write \n or \t instead.No, fix by hand
A second document{"a": 1} {"b": 2}line 1, column 10The JSON is complete before this point, and more text follows it. A JSON text is a single value: put several values in an array, or check one document at a time (JSON Lines files hold one document per line).No, fix by hand

Fix common mistakes changes only what it recognises. It copies every double-quoted string exactly, and text that is already valid comes back unchanged. It cannot know which comma you forgot or which bracket you meant to close, so those stay for you, with the location and the hint.

Valid JSON that another program may still get wrong

Valid is not the same as safe to hand on. RFC 8259 names four things that are allowed by the grammar and still make software disagree, so the validator reports each one next to a valid verdict. None of them changes the text, and none makes it invalid.1

Four kinds of valid JSON the validator warns about, and what it says
Valid JSON that…ExampleWhat the validator saysWhy
A whole number beyond 253 − 1{"id": 12345678901234567890}1 number is beyond what a 64-bit float holds exactly (12345678901234567890). It is kept exactly here, but JSON.parse in a browser or Node would round it.Integers from −9,007,199,254,740,991 to 9,007,199,254,740,991 are interoperable; beyond that, software that reads numbers as 64-bit floats rounds them (RFC 8259, section 6).
A number outside a 64-bit float{"x": 1E400}1 number is outside the range of a 64-bit float (1E400): software that reads it as a float gets Infinity for a huge value and 0 for a tiny one. RFC 8259 names 1E400 as a number that may not survive. It is kept exactly here.RFC 8259 gives 1E400 as an example of a number that may indicate interoperability problems (section 6).
The same key twice{"a": 1, "a": 2}Duplicate key: "a". Most parsers keep only the last value. Both are kept here.Names within an object should be unique; software that receives duplicates behaves unpredictably (section 4).
An unpaired surrogate escape{"s": "\uD800"}1 string contains an unpaired surrogate escape such as \uD800. The text is valid, but RFC 8259 says software that receives it may behave unpredictably, for example by returning different string lengths or failing.The grammar allows it, but the behaviour of software that receives it is unpredictable (section 8.2).

The same text can be read differently by different libraries. Python's json module, for example, accepts NaN, Infinity and -Infinity by default and keeps only the last of a repeated name, while JSON.parse in a browser rejects NaN but rounds a large integer to the nearest 64-bit float without saying so.2

How to validate JSON in JavaScript and Python

In JavaScript, JSON.parse throws a SyntaxError when the text is not valid JSON, so validating is a try and a catch.3

try { JSON.parse(text); console.log("valid"); } catch (e) { console.log(e.name + ": " + e.message); }

The wording of that message depends on the browser and its version, which is why this page finds the position itself and does not read it out of the message.4 In Python, json.loads raises json.JSONDecodeError, which carries the message, the position, the line and the column.2

import json try: json.loads(text) print("valid") except json.JSONDecodeError as e: print(e.msg, e.lineno, e.colno, e.pos)

From a shell, python -m json.tool file.json validates and pretty-prints a file, and prints the line and column of the first error when the file is not valid JSON.2 Neither route tells you about a duplicated key, a number a 64-bit float cannot hold or an unpaired surrogate; the warnings above are the part a plain parse leaves out.

Frequently asked questions

How do I validate JSON?

Paste it into the box at the top of this page. The verdict under the box says Valid JSON or Invalid JSON as you type. For invalid JSON it gives the line and column where parsing stops and a hint, and the Go to the error button selects that character.

What does "Unexpected token" mean in a JSON error?

It means the parser met a character that JSON does not allow at that position, such as a trailing comma, a single quote or a stray letter. Chrome, Edge and Node.js name the token, and current versions quote the start of the text, as in Unexpected token '}'; Firefox words it differently, for example "JSON.parse: unexpected character". This page does not depend on the wording: it finds the position itself and tells you what it expected there.

What does "Unexpected end of JSON input" mean?

The text ended before the JSON was complete: either the box is empty, or something is not closed, such as a bracket, a brace or the closing quote of a string. Which message you see depends on the browser and its version. In Node.js 24, JSON.parse('') gives exactly this message, while a missing closing brace as in {"a": 1 gives "Expected ',' or '}' after property value". A text that stops early is reported as the end of the text, with what is probably missing; an empty box just says there is nothing to check yet.

How do I find the error in a large JSON file?

Open the file with Open a file (up to 20 MB) or paste it, then press Go to the error. The box scrolls to the character where parsing stopped and selects it, and the verdict gives the line and column. A parser stops at the first problem, so fix that one and check again until the verdict says Valid JSON.

Is an empty string, a number or a single word valid JSON?

An empty string is not valid JSON, because a JSON text must contain a value. A single value is: since RFC 7159 and RFC 8259 a JSON text can be any value, so 42, "text", true and null are each valid. The older RFC 4627 required an object or an array at the top level, and some old parsers still insist on it. A bare word such as hello is not a value.

Does the validator accept comments, trailing commas or single quotes (JSONC, JSON5)?

No. It checks strict JSON as RFC 8259 defines it. JSONC and JSON5 allow comments, trailing commas and more, but they are different formats and a strict parser rejects them. Fix common mistakes removes comments and trailing commas and changes single quotes to double quotes, so the text becomes valid JSON.

Why does valid JSON show a warning?

A warning means the text is valid but another program may read it differently. The validator flags four cases that RFC 8259 raises: a whole number beyond 9,007,199,254,740,991, a number outside the range of a 64-bit float such as 1E400, an object with the same key twice, and a string with an unpaired surrogate escape such as \uD800. None of them is a syntax error, and the text is not changed.

Is it a problem if a key appears twice in an object?

The syntax allows it, but RFC 8259 says the names within an object should be unique and that the behaviour of software receiving duplicates is unpredictable: many implementations keep only the last value, others report an error, and some keep all of them. Python's json.loads keeps the last one, for example. The validator names each duplicated key so you can decide which one you meant.

Does it validate against a JSON Schema?

No. This page checks syntax only, which is whether the text is JSON. Whether the data has the right fields and types is a schema check, a separate job that needs a schema as well as the data.

Why does Python's json.loads accept JSON that this validator rejects?

RFC 8259 lets a parser accept some forms beyond the grammar, and Python's json module does by default: it accepts NaN, Infinity and -Infinity, and it accepts repeated names in an object, keeping the last. It does raise an error for a byte-order mark at the start. This validator holds the text to the grammar, so NaN is an error here.

Can I validate a JSON Lines (NDJSON) file?

Not as one piece. A JSON Lines file holds one JSON document per line, so as a whole it is not a single JSON text, and the validator stops at the start of the second line and says the JSON is complete before that point. Paste one line at a time, or in Python use python -m json.tool --json-lines, which parses every line as a separate document.

Is my JSON uploaded or stored?

No. Validating, fixing and opening a file all happen in your browser, and nothing you paste or open is transmitted. We count page visits and button clicks with our own analytics on our own server, and those events carry none of your data.

Sources

  1. Bray, T. (ed.), RFC 8259, The JavaScript Object Notation (JSON) Data Interchange Format (IETF, 2017): the grammar (sections 2 to 7), UTF-8 and byte-order marks (8.1), unpaired surrogates (8.2), and that a parser may accept more than the grammar (9).
  2. Python Software Foundation, json — JSON encoder and decoder: JSONDecodeError and its attributes, the extensions the module accepts by default (NaN, Infinity, repeated names), the byte-order mark, and the command-line tool.
  3. MDN Web Docs, JSON.parse(): a SyntaxError is thrown when the text is not valid JSON.
  4. MDN Web Docs, SyntaxError: JSON.parse: bad parsing: the messages Firefox gives for invalid JSON.

The validator's verdicts, and the line, column and kind of each first error, are checked against Python's own JSON parser on thousands of valid and deliberately broken documents. The hint for each kind of error and the warnings are checked against a second implementation written separately in Python.

Related tools