DEV Community

Avinash Verma
Avinash Verma

Posted on • Originally published at jsonviewertool.com

Common JSON Errors and How to Fix Them (Missing Commas, Quotes, etc.)

JSON is strict. Small mistakes can break your API responses or config files. Here are the most common JSON errors and how to fix them fast.

1. Missing commas between properties

//  Missing comma
{
  "name": "Avi"
  "role": "Developer"
}

//  Fixed
{
  "name": "Avi",
  "role": "Developer"
}
Enter fullscreen mode Exit fullscreen mode

2. Using single instead of double quotes

//  Invalid JSON
{
  'name': 'Avi'
}

//  Valid JSON
{
  "name": "Avi"
}
Enter fullscreen mode Exit fullscreen mode

If a string value itself contains double quotes, backslashes, or newlines, you must escape those characters so the JSON stays valid.

3. Trailing commas

//  Invalid JSON
{
  "name": "Avi",
}

//  Valid JSON
{
  "name": "Avi"
}
Enter fullscreen mode Exit fullscreen mode

4. Unquoted keys

//  Invalid JSON
{
  name: "Avi"
}

//  Valid JSON
{
  "name": "Avi"
}
Enter fullscreen mode Exit fullscreen mode

5. Comments in JSON

JSON does not support comments, even though they are convenient. Attempting to add // comment or /* comment */ will break strict JSON parsing.

//  Not allowed
{
  // user name
  "name": "Avi"
}
Enter fullscreen mode Exit fullscreen mode

Using an online JSON validator

Paste your JSON into the JSON Viewer Tool and click the Validate button. The parser will show you an error message and line/column number so you can fix the problem quickly.

Next steps

Most JSON errors are just small typos. With a good validator and a bit of practice, you'll be able to fix them in seconds and keep your APIs and configs healthy.

Related tools

Top comments (0)