The JSON validator shows the exact line and column of the first error, explains it in plain words, and can repair the usual mistakes. Your JSON never leaves the browser.
Check your JSONStart with the error message, then look one line up
A JSON parser reads from the top and stops at the first character that can't be right. The line and column it reports are where it stopped, which is often just after the real mistake. In this example the comma is missing at the end of line 3:
{
"id": 1,
"title": "Report"
"pages": 12
}The validator reports line 4, column 3: Missing comma between two properties, because it only knows something is wrong when it meets "pages". So when the reported line looks fine, check the end of the line before it.
The mistakes behind most invalid JSON
JSON is stricter than the JavaScript or Python it resembles. RFC 8259, the JSON standard, allows only double-quoted strings, lowercase true, false and null, and commas only between items.
| Mistake | Example | Fix |
|---|---|---|
| Trailing comma | ["a", "b",] | Delete the comma before ] or } |
| Single quotes | {'name': 'Ada'} | Use double quotes for keys and strings |
| Key without quotes | {name: "Ada"} | Quote every key |
| Comments | // settings | Remove them; JSON has no comments |
| Python values | True, None | true, null |
| Curly quotes | “hello” | Straight double quotes, " … " |
| Numbers JSON can't read | .5, 007, NaN | 0.5, "007" (as text, to keep the zeros), null |
| Missing comma | "a": 1 "b": 2 | Add a comma between items |
Fixing JSON from ChatGPT, Claude or Gemini
JSON copied from an AI answer has its own typical problems, on top of the ones above. The answer wraps the JSON in a Markdown code fence and a sentence, and models trained on JavaScript slip in trailing commas:
Here is the JSON:
```json
{
"name": "Ada",
"tags": ["math", "code",],
}
```A strict parser stops at the very first character, the H of “Here”. Try to fix in the validator removes the sentence and the fence and deletes the two trailing commas, leaving valid JSON:
{
"name": "Ada",
"tags": ["math", "code"]
}The other common AI problem is a reply that stops mid-way because it reached its length limit. The JSON then ends inside a string or without its closing brackets.
Check what an automatic repair changed
Repairs are guesses, and most are safe: removing a comment or a trailing comma can't change your data. Two kinds need a human look. Take this cut-off reply:
{
"items": [
{"id": 1, "name": "Lamp"},
{"id": 2, "name": "CabTry to fix closes the string and the brackets, so the result is valid, and lists both changes. But the second item now has the name "Cab", and whatever came after it is gone. Valid is not the same as complete. Ask the assistant to continue, or to send the JSON again in smaller parts.
The second kind is a missing comma or quote in the middle of a document, where the repair has to decide where one value ends and the next begins. Read the list of changes, and compare the item count with what you expected. If you need to see exactly what moved, put the original and the repaired version side by side in JSON diff once both parse.
Valid JSON that a program still rejects
- Duplicate keys. The standard says names should be unique but doesn't forbid repeats. JavaScript and Python keep the last value without warning. The validator flags them.
- A byte order mark. The standard says JSON sent between systems must not start with one, and Python's
json.loadsrefuses a string that starts with one. Save the file as UTF-8 without a BOM. - Big numbers. IDs above 9,007,199,254,740,991 lose their last digits in JavaScript. Send them as strings.
- Lenient parsers. Python accepts
NaNandInfinityby default, so a file can work in one program and fail in another. Check against the standard, not one parser.
Once it's valid, the JSON formatter lays it out with indentation so it's easy to read and review.
Sources
- RFC 8259: The JavaScript Object Notation (JSON) Data Interchange Format
- Python documentation: json. NaN, duplicate keys and the BOM