How to Fix Common JSON Syntax Errors
This guide was prepared by the WebToolkit team and reviewed against the current behavior of the related tool.
JSON is strict about its syntax. A single misplaced character, such as a stray comma or the wrong kind of quotation mark, can make an entire document invalid and cause a parser to reject it. The good news is that most JSON errors fall into a small number of well-known categories, and once you recognize them they are quick to fix.
This guide walks through the most common JSON syntax errors with clear before-and-after examples, then shows how to validate your JSON to find the exact problem.
What valid JSON looks like
Here is a small, valid JSON object to use as a reference:
{
"name": "sample-config",
"active": true,
"tags": ["json", "config"],
"retries": 3
}A few rules define valid JSON:
- Objects use braces { }.
- Arrays use square brackets [ ].
- Keys are written in double quotes.
- Strings are written in double quotes.
- Commas separate items, but there is no comma after the last item.
- Values can be a string, number, object, array, true, false, or null.
Error 1 — Single quotes instead of double quotes
JSON requires double quotes for keys and string values. Single quotes are valid in JavaScript but not in JSON.
{
'name': 'WebToolkit'
}{
"name": "WebToolkit"
}Error 2 — Missing comma
Each property in an object must be separated from the next by a comma.
{
"name": "WebToolkit"
"active": true
}{
"name": "WebToolkit",
"active": true
}Error 3 — Trailing comma
Standard JSON does not allow a comma after the final item in an object or array.
{
"name": "WebToolkit",
"active": true,
}{
"name": "WebToolkit",
"active": true
}Error 4 — Unquoted property names
Keys must always be quoted in JSON, even when they contain no spaces.
{
name: "WebToolkit"
}{
"name": "WebToolkit"
}Error 5 — Mismatched braces or brackets
Every opening brace or bracket needs a matching closing one, and they must be nested correctly.
{
"tags": ["json", "config"
}{
"tags": ["json", "config"]
}Error 6 — Invalid escape characters
Certain characters inside strings must be escaped with a backslash. The most common are the double quote, the backslash itself, and control characters such as a newline.
- A double quote inside a string is written as \"
- A backslash is written as \\
- A newline is written as \n
{
"quote": "She said \"hello\"",
"path": "C:\\Users\\Public"
}Error 7 — Comments inside JSON
Standard JSON does not support JavaScript-style comments. Lines beginning with // or blocks wrapped in /* */ will cause an error.
{
// the application name
"name": "WebToolkit"
}Error 8 — Undefined, NaN, or functions
Values like undefined, NaN, and functions are JavaScript constructs, not valid JSON values. If you need to represent a missing value, use null.
- Valid JSON values are: string, number, object, array, true, false, and null.
- Replace undefined or NaN with a valid value such as null or a real number.
Error 9 — Multiple top-level values
A JSON document normally contains a single top-level value. Two objects placed side by side, without being wrapped in an array, are not valid.
{ "id": 1 }
{ "id": 2 }[
{ "id": 1 },
{ "id": 2 }
]Understanding parser error messages
Parsers describe problems in slightly different ways, but common messages point you to the cause:
- "Unexpected token" usually means a character appears where the parser did not expect it, often near a missing comma or an extra one.
- "Unexpected end of JSON input" often means a brace or bracket was never closed.
- "Expected property name" points to a key that is missing or not quoted.
- "Invalid character" suggests a stray or unescaped character in the text.
Exact wording and character positions can differ between browsers and tools, so treat the message as a strong hint about where to look rather than a fixed script.
How to validate JSON with WebToolkit
- Paste your JSON into the input editor.
- Choose Validate or Format.
- Read the syntax error message the tool reports.
- Correct the relevant character or structure.
- Validate again to confirm it now parses.
- Copy or download the cleaned-up result.
You can do this with the JSON Formatter and validator, which reports where the syntax is wrong so you can fix it quickly.
How your data is handled
Your JSON is sent to the server to produce the result, parsed as data with JSON.parse, and never executed as code. WebToolkit does not intentionally save the submitted JSON.
As a general habit, do not paste passwords, API secrets, or confidential tokens into any online tool.
Validate and format your JSON
Find the exact syntax error, beautify with readable indentation, or minify for production.
JSON troubleshooting checklist
- Use double quotes for keys and strings.
- Check that commas separate every item.
- Remove any trailing commas.
- Match every brace and bracket.
- Escape special characters inside strings.
- Remove comments.
- Replace undefined or NaN with a valid value.
- Ensure there is only one top-level value.
Frequently asked questions
Why is my JSON invalid?
The most common causes are single quotes, a missing or trailing comma, unquoted keys, or a mismatched brace or bracket. A validator will point you to the specific location.
Can JSON use single quotes?
No. JSON requires double quotes for both keys and string values. Single quotes are valid in JavaScript but not in JSON.
Are trailing commas allowed?
No. Standard JSON does not permit a comma after the last item in an object or array. Remove it to make the JSON valid.
Can JSON contain comments?
Standard JSON does not support comments. Remove // and /* */ style comments, or store the note as a regular string value if you need to keep it.
What does "unexpected token" mean?
It means the parser found a character where it did not expect one. This often happens near a missing comma, an extra comma, or a wrong quotation mark.
Can a formatter automatically repair JSON?
The JSON Formatter reports syntax errors so you can correct them, but it does not automatically rewrite or repair invalid JSON for you.
Is it safe to paste JSON into the validator?
Your JSON is processed only to return the result and is not intentionally saved. As a precaution, avoid pasting passwords, secrets, or confidential tokens into any online tool.
Conclusion
Most JSON errors come down to quotes, commas, brackets, and unsupported values. Keep the troubleshooting checklist handy, and when an error is hard to spot, paste the JSON into a validator to find the exact character that needs fixing.