Unexpected token is the most common JSON parse error message you will encounter, and it is also the most under-explained.
Loading JSON Validator…
Shows exactly which character is unexpected
Explains why each token type causes an error
Reports line and column, not just position offset
Free, browser-based, no installation
Drop the JSON Validator into any page — blog post, product docs, intranet, school portal — with a single line of HTML. Your visitors get the full tool, processed entirely in their browser. No backend, no uploads, no signup.
Embed code
<iframe
src="https://www.fixtools.io/json/json-validator?embed=1"
width="100%"
height="780"
frameborder="0"
style="border:0;border-radius:16px;max-width:900px;"
title="JSON Validator by FixTools"
loading="lazy"
allow="clipboard-write"
></iframe>Attribution-friendly: a small "Powered by FixTools" link appears in the embed footer.
The phrase Unexpected token covers many distinct root causes, and the character named in the message identifies which one applies. A closing brace or bracket means the parser hit a closing character immediately after a comma, which is the trailing comma signature: delete the comma. A comma means two commas appear in a row or a comma appears at the start of an array: remove the duplicate or the leading separator. A single quote means a developer wrote a string with the wrong quote character: replace single quotes with double quotes on strings and property names. A leading letter that begins the word undefined, the word NaN, or the word Infinity means a serialiser emitted a JavaScript literal that has no JSON equivalent: replace the value with null or with an appropriate placeholder.
Other token types point to different categories of problem. A less-than sign at position zero means the response is actually HTML, not JSON: the server returned an error page or a redirect, and the fix is on the server side or in the client request, not in the JSON itself. An opening parenthesis at position zero means the content is wrapped in a JSONP callback: strip the wrapper function call to recover the inner JSON. The text slash-slash or slash-star means a JavaScript comment was embedded in the JSON document: comments are not permitted in JSON, so remove them. The text end of input means a bracket, brace, or string was opened but never closed: count the openers and closers to find the imbalance.
The position in the error message is the single most diagnostic piece of information. Position zero almost always means the content is not JSON at all and you should investigate the source of the data rather than its syntax. Any other position points to a specific character in the body that broke the parse. That character either is wrong for its position, in which case you replace it, or it reveals that something earlier or later is wrong, in which case the fix may be a few characters away. FixTools converts the offset to a real line and column, categorises the token type, and explains the most likely cause so the path from error to fix is as short as the data permits.
After diagnosing and fixing an unexpected token error in the moment, the durable next step is to wire validation into a CI pipeline so the same class of failure cannot reach the main branch again. A typical GitHub Actions or GitLab CI job runs jq . or python3 -m json.tool over every JSON file changed in a pull request and exits with a non-zero status on the first failure, blocking the merge until the issue is fixed. Pre-commit hooks using the check-json hook from the standard pre-commit framework catch the failure on the developer machine before the commit reaches the remote at all. For runtime JSON arriving over the wire from external systems, a validation middleware catches parse failures, logs the raw input alongside the error message, and returns a structured 400 to the client. Layering pre-commit, CI, and runtime validation produces a defence in depth that turns unexpected token errors from recurring debugging cost into invisible plumbing the team never has to think about again.
Paste the JSON that is giving you an Unexpected token error. FixTools identifies the exact token, explains why it is invalid, and tells you what to fix.
Step-by-step guide to fix json unexpected token:
Paste the failing JSON
Copy the exact JSON string that produced the Unexpected token error from your application logs, your terminal, or your editor. Paste the full content into the FixTools input area so the validator can scan the entire structure. Include any leading or trailing whitespace that was in the original because the validator needs the same bytes the parser saw to reproduce the failure faithfully.
Run validation
Click the Validate button to run the check. The validator reports three pieces of information: the line and column where parsing failed, the unexpected character that was found at that position, and a description of the most likely cause. The combination is enough to determine the fix without further investigation in the majority of cases, which is the goal of the tool.
Identify the token type
Look at the unexpected character that the validator named. A closing brace or bracket indicates a trailing comma immediately before it. A single quote indicates a wrong quote style. A leading letter such as u or N indicates a JavaScript literal that does not exist in JSON. A less-than sign at position zero indicates HTML rather than JSON. Each token type has a different fix, and recognising the type is the key step before editing.
Apply the fix
Edit the source at the exact location the validator reported. For a trailing comma, delete the comma before the bracket. For wrong quotes, replace the single quotes with double quotes. For a JavaScript literal, replace it with null or with an appropriate value. For an HTML response, investigate why the server returned the wrong content type. Save the file and prepare to revalidate to confirm the fix worked and no other errors were waiting behind it.
Revalidate
Paste the updated content into FixTools and run validation again. JSON parsers fail fast, so the first fix may unveil further errors that were hidden until the first one was resolved. Repeat the fix-and-revalidate cycle, addressing each reported error one at a time in order, until the validator returns a green result indicating the entire document conforms to RFC 8259.
Common situations where this approach makes a real difference:
API developer
A developer integrates with a third-party API and starts seeing SyntaxError: Unexpected token T at runtime in production. They capture a failing response and paste it into FixTools. The validator highlights the literal text True with a capital T at line 34 in a boolean field. The API is serialising Python booleans directly, using the Python convention of capitalised first letters, rather than the JSON lowercase form. The developer adds a normalisation step that lowercases known Python literals before parsing, while filing a bug with the vendor to fix the serialiser at its source.
Full-stack developer
A developer writes a template that generates JSON config files from user input. One field contains a multi-line description that includes literal newline characters. The config loader rejects the file with Unexpected token at line eight column 23. FixTools highlights an unescaped newline inside a string value. The template was concatenating raw text into the JSON instead of running it through JSON.stringify, which would have produced the proper escape sequence. Switching the template to use JSON.stringify for value content fixes the issue and any future special characters.
Data engineer
A data export pipeline produces JSON files with numeric fields set to the literal text NaN where sensors failed to report. Downstream systems reject the files with Unexpected token N. The engineer adds a post-processing step that walks the structure and replaces NaN, Infinity, and negative Infinity with null in any numeric field before writing. They validate a representative sample in FixTools to confirm the replacement makes the files parseable, then deploy the fix to production and reprocess the backlog of rejected files.
Student developer
A student is writing their first API client in Node.js and hand-writes a test request body in a text file using Python conventions for booleans because their previous course was in Python. Their test client throws SyntaxError: Unexpected token T. They paste the body into FixTools and immediately see the capitalised True flagged with an explanation that JSON booleans must be lowercase. They fix the file, learn the rule, and move on. The visual highlighting and plain-language explanation made the rule stick faster than reading the JSON specification ever could.
Get better results with these expert suggestions:
The token character is your primary clue
The character named in the Unexpected token error tells you the fix category immediately. A less-than sign means the response is HTML rather than JSON. A single quote means wrong quote style. The letter u means undefined was emitted as a literal. The letter N means NaN. A closing brace or bracket means a trailing comma sits just before it. Memorising these mappings lets you guess the fix category before you even paste into the validator, which saves time on routine cases.
Position zero errors are always content-type issues
When the parse error position is zero, the entire input is wrong rather than just one character. The first byte of the buffer is not a valid JSON start character. The fix is not to look for a syntax error somewhere in the document but to investigate why the content is wrong: a 404 page from the server, a redirect to a login page, a JSONP wrapper, a BOM byte from a UTF-8-with-BOM file, or a Content-Type mismatch. Inspect the source of the data rather than its syntax.
End of input errors mean unclosed structures
The message Unexpected end of input or Unexpected end of JSON input signals that a brace, bracket, or string was opened during parsing and was never closed before the buffer ran out. Count the open braces against the close braces in your document, and the open brackets against the close brackets. The structure with the unmatched opener is the one missing its closer. A formatter that re-indents the document by nesting level usually reveals the imbalance visually.
Check keyword capitalisation for non-JavaScript languages
JSON output produced by Python serialisers may contain True, False, or None instead of the JSON lowercase true, false, and null. Ruby produces nil where JSON expects null. Java sometimes produces Boolean.TRUE instead of the lowercase literal when toString is overridden. Swift produces nil. Each language has its own conventions, and JSON serialisers in each language can sometimes leak the source convention into the output. Validate JSON that crosses language boundaries rather than trusting the producer to handle the edge cases correctly.
More use-case guides for the same tool:
Other tools you might find useful:
Open the full JSON Validator — free, no account needed, works on any device.
Open JSON Validator →Free · No account needed · Works on any device