Need help with your JSON?
Try our JSON Formatter tool to automatically identify and fix syntax errors in your JSON. JSON Formatter tool
Common JSON Syntax Errors and How to Fix Them
Most invalid JSON comes down to a short list of problems: missing commas, unmatched braces, wrong quotes, broken escape sequences, or JavaScript-style extras such as comments and trailing commas. If your parser says the file is invalid, the fastest path is to validate the structure first, then check whether you are working with strict JSON or a more forgiving format like JSON with Comments.
This guide focuses on the errors people hit most often when pasting API payloads, config files, and copied snippets into a formatter, editor, or build pipeline. It also includes practical tips for troubleshooting JSON in VS Code and for displaying highlighted JSON on a web page without confusing presentation with valid data.
Start Here: Find the Error Faster
- Paste the content into a validator or formatter so the parser can point to the first broken token.
- Check one line above the reported line, because a missing comma or quote often breaks the next line.
- Make sure the file is really strict JSON and not JSONC, JavaScript, or a template fragment.
- After each fix, validate again immediately instead of changing multiple things at once.
1. Missing or Extra Commas
Every object member and array element is separated by a comma, but the final item does not get one. A missing comma usually produces an error on the following line, which is why it can feel like the parser is pointing to the wrong place.
Incorrect:
{
"name": "John",
"age": 30,
"city": "New York"
"country": "USA"
}Corrected:
{
"name": "John",
"age": 30,
"city": "New York",
"country": "USA"
}Incorrect:
{
"fruits": [
"apple",
"banana",
"orange",
]
}Corrected:
{
"fruits": [
"apple",
"banana",
"orange"
]
}2. Comments and Trailing Commas Copied from JSONC
A very common source of confusion is copying content from tools that allow comments or trailing commas. Those files may look like JSON, but strict parsers reject them. This happens often with editor settings and config files that use JSON with Comments.
Incorrect:
{
// Local development override
"host": "localhost",
"port": 3000,
}Corrected:
{
"host": "localhost",
"port": 3000
}If VS Code seems happy with comments or trailing commas, check the language mode in the status bar. You may be editing the file as JSON with Comments instead of strict JSON.
3. Unclosed Brackets and Braces
Every opening bracket or brace must have a matching closing character. One missing ] or } can make the rest of the document look invalid.
Incorrect:
{
"person": {
"name": "Alice",
"hobbies": ["reading", "hiking"
}
}Corrected:
{
"person": {
"name": "Alice",
"hobbies": ["reading", "hiking"]
}
}4. Strings and Property Names Must Use Double Quotes
JSON is stricter than JavaScript object literals. Property names must be quoted, and both keys and string values must use double quotes.
Incorrect:
{
name: 'Bob',
"email": 'bob@example.com'
}Corrected:
{
"name": "Bob",
"email": "bob@example.com"
}5. Invalid Escape Sequences and Broken Strings
JSON strings cannot contain unescaped double quotes, raw backslashes in Windows paths, or literal line breaks. If a string contains special characters, escape them explicitly.
Incorrect:
{
"message": "He said "Hello" to me",
"path": "C:\Users\Documents"
}Corrected:
{
"message": "He said \"Hello\" to me",
"path": "C:\\Users\\Documents"
}6. Invalid Numbers and Non-JSON Values
JSON supports numbers, booleans, and null, but the grammar is narrower than JavaScript. Leading plus signs, leading zeros, trailing decimal points, and values like undefined, NaN, and Infinity are not valid JSON.
- No leading + sign
- No leading zeros (except for decimal numbers less than 1)
- No trailing decimal point
- Use lowercase
true,false, andnull
Incorrect:
{
"price": +42.00,
"quantity": 007,
"discount": 10.,
"active": True,
"fallback": undefined
}Corrected:
{
"price": 42.00,
"quantity": 7,
"discount": 10.0,
"active": true,
"fallback": null
}7. Duplicate Keys Are Not a Syntax Error, but Still a Bug
Some parsers accept duplicate object keys, but the result is unreliable because different systems may keep the last value, the first value, or reject the object entirely. Even if the file parses, duplicated keys are a data quality problem worth fixing immediately.
Incorrect:
{
"timeout": 15,
"timeout": 30,
"baseUrl": "https://api.example.com"
}Corrected:
{
"timeout": 30,
"baseUrl": "https://api.example.com"
}Troubleshooting JSON Syntax in VS Code
VS Code has strong built-in JSON support, but a few editor details matter when you are chasing syntax errors.
- Check the language mode in the status bar. Use
JSONfor strict data andJSON with Commentsonly for files that intentionally allow comments and trailing commas. - Run
Format Document. Broken indentation often makes the missing bracket, quote, or comma easy to spot. - Open the Problems panel and hover the red squiggles. VS Code reports both structural issues and schema-based validation problems.
- If a custom file extension is not being checked as JSON, map it with
files.associations. - If you expect validation but see nothing, confirm that
json.validate.enableis turned on.
Can CSS Syntax-Highlight Raw JSON by Itself?
Not really. CSS can color already-marked-up tokens, but it does not parse raw JSON text into keys, strings, numbers, and punctuation on its own. If you want syntax-highlighted JSON on a web page, you usually need one of these approaches:
- Render the JSON through a syntax highlighter that wraps tokens in HTML elements with classes.
- Show plain JSON in a code block and let the user rely on their editor, browser extension, or devtools.
- Store the raw JSON as data, then generate separate presentation markup so users can still copy valid JSON.
If your goal is readability instead of decorative coloring, formatting the indentation and validating the JSON first usually delivers more value than adding CSS alone.
JSON Fix Checklist
- Every object key is wrapped in double quotes.
- Every item except the last has a comma after it.
- All opening braces and brackets have matching closing characters.
- Strings escape quotes, backslashes, and control characters correctly.
- No comments, trailing commas,
undefined,NaN, orInfinity. - Boolean and null literals are lowercase:
true,false, andnull. - Object keys are unique before you ship or save the payload.
When in doubt, paste the payload into our JSON formatter, fix the first reported issue, and re-run validation after each change. Small, sequential fixes are much faster than trying to repair a broken document by eye.
Why These Rules Matter
JSON parsers follow a strict grammar so data can move predictably between tools, languages, and APIs. That is why small-looking differences, such as single quotes, comments, or duplicate keys, can break imports, cause rejected API requests, or create subtle bugs across different environments.
If you are bouncing between browser payloads, config files, and editor settings, assume nothing. Validate the content as strict JSON first, then decide whether the file actually belongs in JSONC or another format.
Need help with your JSON?
Try our JSON Formatter tool to automatically identify and fix syntax errors in your JSON. JSON Formatter tool