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.

Beginner9 min read

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.

Invalid: missing comma
{
  "name": "Ari"
  "active": true
}
Corrected JSON
{
  "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.

Invalid: colon missing after key
{
  "city" "Oslo"
}
Corrected JSON
{
  "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.

Invalid: JavaScript-style single quotes
{ 'name': 'Ari' }
Corrected JSON
{ "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.

Invalid: comma after the final array item
{
  "colors": ["teal", "amber",]
}
Corrected JSON
{
  "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.

Invalid: bare key
{ name: "Ari" }
Corrected JSON
{ "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.

Invalid: JavaScript comment
{
  "mode": "test" // remove this comment
}
Corrected JSON
{
  "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.

Correct nested JSON
{
  "items": [
    {
      "name": "Notebook",
      "tags": ["paper", "office"]
    }
  ]
}

A step-by-step debugging workflow

  1. Copy the source into a local editor or the JSON Validator. Avoid changing multiple things at once.
  2. Read the error location as a clue. Parsers often point near where parsing became impossible, which can be after the original mistake.
  3. Check the closest opening and closing braces or brackets, then inspect the preceding property or array item.
  4. Check double quotes, colons, and commas. Look for trailing commas and comments.
  5. Validate again after each correction. Once parsing succeeds, use the JSON Formatter to make the structure easier to inspect.
  6. 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.
Syntax versus data rules: A JSON Validator checks whether the text parses as JSON. It does not know whether a field is required by your application, whether an email is meaningful, or whether a number is within your business limits. A schema can express some of those structural rules.

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.