PrivTab

یہ صفحہ فی الحال انگریزی میں ہے۔

Fix Invalid JSON: The 8 Most Common Errors and How to Spot Them

· 3 min read

"Unexpected token", "Unexpected end of JSON input", "Expected double-quoted property name": JSON errors are among the most common reasons an API request fails or an app won't start after a config change. JSON's rules are strict but few, so once you know the usual suspects, most errors take seconds to fix.

Find the error

  1. Paste your JSON into the JSON Validator.
  2. If it's invalid, you get the exact line and column of the error.
  3. Fix it and validate again. Optionally format it after validating.

The validator follows standard JSON as defined in RFC 8259, the same rules web browsers use. The JSON Formatter also shows the line and column of errors, and formats valid JSON with 2 spaces, 4 spaces or tabs, or minifies it.

Note that the reported position is where the parser noticed the problem. The actual mistake is often just before it, for example a missing comma on the previous line.

The 8 most common JSON errors

1. Trailing commas

{ "name": "Asha", "age": 31, }

JavaScript allows a comma after the last item; JSON doesn't. Remove it.

2. Single quotes

{ 'name': 'Asha' }

JSON strings and keys must use double quotes: "name".

3. Unquoted keys

{ name: "Asha" }

Every key must be a double-quoted string.

4. Comments

{ "debug": true // turn off in production }

Standard JSON has no comments. Remove them, or use a format that allows them, such as JSONC for some editor settings, if the program supports it.

5. Missing commas

{ "a": 1 "b": 2 }

Items in objects and arrays must be separated by commas.

6. Unescaped characters in strings

Double quotes and backslashes inside strings must be escaped: "He said \"hi\"", "C:\\Users". Literal line breaks inside a string aren't allowed; use \n.

7. Invalid values

undefined, NaN, Infinity, functions and dates aren't JSON values. Use null, numbers, strings, booleans, arrays and objects only. Dates are usually written as ISO 8601 strings: "2026-10-18T09:00:00Z".

8. Truncated JSON

"Unexpected end of input" usually means the JSON was cut off: a missing closing } or ], or a response that didn't arrive completely. Check the end of the data, or how it was copied or downloaded.

Format for reading, minify for sending

  • Formatting adds line breaks and indentation, making nested data readable and errors easier to spot.
  • Minifying removes unnecessary whitespace to make the data as small as possible, for example for sending over a network or storing in a single line.

Neither changes the data itself.

Tips to avoid JSON errors

  • Generate JSON with your language's built-in serializer (JSON.stringify, json.dumps) instead of building it by hand with string concatenation.
  • Validate config files before deploying.
  • Use an editor with JSON syntax highlighting; most show errors as you type.

Common questions

Does the validator fix my JSON automatically? No. It shows exactly where the error is so you can fix it, which avoids silently changing your data.

Is my JSON uploaded? No. Everything runs in your browser, so API responses with tokens or personal data stay on your device.

Summary

  • Validate to get the line and column.
  • Look just before the reported position.
  • Trailing commas, single quotes and comments are the usual culprits.

DevelopersJSON

Tools used in this guide

← All guides