ToolTapGo guide

Common JSON Errors and How to Fix Them

Fix trailing commas, invalid quotes, missing brackets and other JSON syntax problems with clear examples.

ToolTapGo

JSON is strict. A file can look almost correct to a person and still fail to parse because of one comma, quote or bracket. A validator points to the approximate position, but understanding the common mistakes makes the repair much faster.

Use double quotes

JSON property names and string values use double quotes. This is invalid:

{'name': 'ToolTapGo'}

Use:

{"name": "ToolTapGo"}

Remove trailing commas

A comma must separate values, not follow the final value.

{
  "name": "ToolTapGo",
  "active": true
}

Match every bracket

Objects use braces { } and arrays use square brackets [ ]. Indenting the document makes a missing closing character easier to spot.

Escape characters inside strings

A literal double quote inside a JSON string must be escaped with a backslash. New lines and backslashes also need valid escape sequences.

{"message": "He said \"hello\"."}

Use valid values

JSON supports strings, numbers, objects, arrays, true, false and null. JavaScript values such as undefined, NaN, comments and functions are not valid JSON.

Debugging workflow

  1. Paste the document into the JSON Viewer.
  2. Read the first syntax error rather than fixing several guesses at once.
  3. Check the character immediately before and after the reported position.
  4. Format the valid document to expose the hierarchy.
  5. Compare keys and value types with the API or schema you are using.

Parsing versus validation

A document can be valid JSON but still contain the wrong fields for an application. Syntax validation confirms that the structure can be parsed; schema or application validation confirms that the values are acceptable for the intended system.

Further reading

MDN documents the errors thrown when JSON.parse() receives invalid JSON: JSON.parse bad parsing errors.

Found this guide useful?

Share this article or continue with the relevant ToolTapGo tool.

Browse related tools