VALIDATION
How to Find and Fix JSON Syntax Errors
A single misplaced comma or quote can make an otherwise useful document impossible to parse. This guide shows the mistakes most often caused by confusing JSON with JavaScript, and a step-by-step way to locate them.
JSON is stricter than JavaScript objects
JSON is a text data format with its own grammar. JavaScript object literals allow conveniences that JSON does not, such as unquoted identifier keys, single-quoted strings, comments, and trailing commas. A JavaScript snippet that looks object-like is not necessarily valid JSON.
Each incorrect snippet below is shown as plain text, not as a valid JSON code sample. The corrected snippet is JSON and can be copied or sent to the RomitJSON Formatter.
1. Missing commas between properties or items
Use a comma between neighboring object properties or array values. Do not add one after the final value.
{
"name": "Ari"
"active": true
}{
"name": "Ari",
"active": true
}2. Missing or misplaced colons
A colon separates each object key from its value. A comma separates complete key-value pairs.
{
"city" "Oslo"
}{
"city": "Oslo"
}3. Single quotes instead of double quotes
JSON strings and object keys must use double quotation marks. Apostrophes can appear inside a double-quoted JSON string without being escaped.
{ 'name': 'Ari' }{ "name": "Ari" }4. Trailing commas
The last property or array item must not be followed by a comma. A trailing comma is accepted in some programming languages but not in standard JSON.
{
"colors": ["teal", "amber",]
}{
"colors": ["teal", "amber"]
}5. Unquoted property names
Every object key must be a JSON string in double quotes, even when it contains only letters and would be a valid JavaScript identifier.
{ name: "Ari" }{ "name": "Ari" }6. Comments or extra text
Standard JSON has no comment syntax. Remove // and /* ... */ comments before parsing. If a note must travel with the data, represent it as a regular property only when the consuming application expects that property.
{
"mode": "test" // remove this comment
}{
"mode": "test"
}7. Mismatched braces and brackets
Objects begin with { and end with }; arrays begin with [ and end with ]. Close nested values in reverse order, and check that every opening delimiter has its matching closing delimiter.
{
"items": [
{
"name": "Notebook",
"tags": ["paper", "office"]
}
]
}A step-by-step debugging workflow
- Copy the source into a local editor or the JSON Validator. Avoid changing multiple things at once.
- Read the error location as a clue. Parsers often point near where parsing became impossible, which can be after the original mistake.
- Check the closest opening and closing braces or brackets, then inspect the preceding property or array item.
- Check double quotes, colons, and commas. Look for trailing commas and comments.
- Validate again after each correction. Once parsing succeeds, use the JSON Formatter to make the structure easier to inspect.
- If the syntax is valid but the values are wrong, compare the document against the expected data shape; syntax validation does not prove that the data is semantically correct.
Key takeaways
- Use double quotes for all keys and string values.
- Separate entries with commas; do not add a comma after the last one.
- Use a colon between each key and value.
- Remove comments and make sure delimiters are paired.
- Validate syntax, then separately check application-specific expectations.