Quick answer
The JSON "unexpected token" error means the parser encountered a character it did not expect at that position, often due to a comma, quote, or bracket issue.
JSON Unexpected Token Error
Unexpected token is one of the most common JSON errors. It usually means the parser hit a character or symbol it did not expect at the current position.
Common causes
- Missing or extra comma between properties.
- Trailing comma after the last array or object element.
- Single quotes instead of double quotes for strings.
- Unescaped special character inside a string.
How to fix
- Run your JSON through an online validator to get the exact line and column.
- Use double quotes for all keys and string values.
- Remove trailing commas and ensure commas only between elements.
- Escape backslashes and quotes inside strings.
Examples
Bad
{"a": 1, "b": 2,}Good
{"a": 1, "b": 2}JSON unexpected token errors happen when a parser encounters a character, symbol, or structure that does not match valid JSON syntax at the current position. This is one of the most common issues developers see when working with APIs, configuration files, request payloads, and data exports. It often points to a formatting problem such as a missing quote, trailing comma, unescaped character, or malformed value. This page explains what the error means, how to identify the likely cause, and how to correct it safely so your JSON can be parsed by browsers, servers, and application code.
How This Validator Works
This page helps you understand and troubleshoot JSON parsing failures by mapping the error message to common syntax rules. JSON is strict: keys must be in double quotes, strings must be properly escaped, values must use valid types, and punctuation must follow the expected structure. When a parser reports an unexpected token, it is usually telling you that the next character does not fit the grammar at that point in the document.
- Checks for syntax patterns that commonly trigger parse errors
- Helps you locate the position where parsing stopped
- Explains what the token may represent in context
- Supports debugging of API responses, config files, and embedded JSON
Common Validation Errors
- Missing double quotes around keys — JSON requires object keys like "name", not name.
- Trailing commas — a comma after the last item in an object or array can trigger a parse failure.
- Single quotes — JSON does not allow single-quoted strings.
- Unescaped characters — quotes, backslashes, and control characters inside strings must be escaped correctly.
- Unexpected letters or symbols — values such as undefined, NaN, or stray punctuation are not valid JSON tokens.
- Missing colon or comma — object members and array items must be separated with the correct punctuation.
- Incomplete JSON — truncated payloads, missing braces, or cut-off strings often produce unexpected token errors.
Where This Validator Is Commonly Used
- API request and response debugging
- Frontend applications using fetch, XMLHttpRequest, or JSON.parse()
- Server-side parsing in Node.js, Python, PHP, Java, and Go
- Configuration files and environment-driven settings
- Webhook payload inspection
- Data import/export pipelines
- Testing structured data in development and QA workflows
Why Validation Matters
Valid JSON is important because many systems depend on it as a machine-readable interchange format. A single syntax issue can break an API call, prevent a configuration file from loading, or cause a frontend application to fail when reading data. Validation helps teams catch formatting mistakes early, reduce debugging time, and avoid silent failures in production workflows. It also improves reliability when JSON is generated by templates, external services, or user input.
Technical Details
| Format | JSON (JavaScript Object Notation) |
| Parser behavior | Parsing stops when a character does not match the expected JSON grammar |
| Common token types | Strings, numbers, booleans, null, objects, arrays, punctuation |
| Typical error sources | Malformed syntax, invalid escaping, truncated content, unsupported values |
| Related standards | JSON syntax as commonly implemented by language parsers and APIs |
In many environments, the error message includes a position, line number, or column number. That location is usually the best place to inspect first, but the actual mistake may be just before the reported token. For example, a missing quote earlier in the document can cause the parser to misread everything that follows.
FAQ
What does “unexpected token” mean in JSON?
It means the JSON parser found a character or symbol that is not valid at that point in the document. The token may be a letter, quote, comma, brace, or bracket. In practice, this usually points to a syntax issue such as a missing quote, trailing comma, or malformed value.
Why does JSON.parse() throw an unexpected token error?
JSON.parse() throws this error when the input string is not valid JSON. Common causes include single quotes, unescaped characters, extra commas, or non-JSON values like undefined. The parser expects strict JSON syntax and will stop as soon as it encounters something that does not fit the grammar.
Is an unexpected token error always caused by bad JSON?
Usually, yes, but not always in the same place the error is reported. Sometimes the real issue is earlier in the document, such as an unclosed string or missing delimiter. In other cases, the input may not be JSON at all, even if it looks similar to JavaScript object syntax.
What is the most common cause of JSON syntax errors?
One of the most common causes is using JavaScript object syntax instead of strict JSON. For example, JSON requires double quotes around keys and string values, and it does not allow comments or trailing commas. These differences often lead to unexpected token errors when data is copied from code into a JSON parser.
How do I find the exact location of the error?
Check the line, column, or character position reported by the parser if available. Then inspect the surrounding text for missing punctuation, unescaped quotes, or truncated content. If the parser reports a token near the end of the file, the issue may be an incomplete object, array, or string earlier in the payload.
Can HTML or special characters break JSON?
Yes, if they are inserted into a JSON string without proper escaping. Characters such as double quotes, backslashes, and control characters must be escaped. Raw HTML can also create problems if it contains unescaped quotes or line breaks inside a JSON string value.
What is the difference between JSON and JavaScript objects?
They look similar, but JSON is stricter. JSON only allows double-quoted strings, valid primitive values, and a limited set of punctuation. JavaScript objects can include single quotes, functions, comments, and undefined values, which are not valid in JSON. Copying object literals directly into JSON often causes parse errors.
Can a server send invalid JSON?
Yes. APIs sometimes return malformed JSON because of backend bugs, template issues, encoding problems, or partial responses. If a client receives invalid JSON, the parser will fail even if the request itself was correct. Checking the raw response body is often the fastest way to confirm the problem.
How can I prevent unexpected token errors?
Use a JSON validator during development, generate JSON with serializers instead of manual string building, and test API payloads before deployment. It also helps to lint configuration files, escape dynamic content correctly, and avoid mixing JavaScript syntax with JSON syntax in stored data or responses.
Related Validators & Checkers
- JSON Validator — check whether a JSON document is syntactically valid
- XML Validator — inspect markup structure and parsing issues in XML documents
- Schema Validator — validate structured data against a defined schema
- API Response Checker — review response formatting and payload integrity
- Syntax Validator — identify common formatting and parsing problems across data formats
FAQ
- What does unexpected token mean in JSON?
- The parser encountered a character it did not expect at that position, often a comma, quote, or bracket issue.
- How do I find the unexpected token?
- Use a JSON validator; it will report the line and column of the error.
Fix it now
Try in validator (prefill this example)