How to Read and Fix JSON Syntax Errors
JSON looks simple until a single misplaced comma breaks an import, an API request or a configuration file. The good news is that almost every JSON error comes from a short list…
On this page
JSON looks simple until a single misplaced comma breaks an import, an API request or a configuration file. The good news is that almost every JSON error comes from a short list of causes. This guide shows how to read parser error messages and fix the mistakes that cause them.
The rules JSON actually enforces
- Strings and object keys use double quotes. Single quotes are invalid.
- No trailing commas after the last item in an object or array.
- No comments. Neither // nor /* */ is allowed.
- Values are only strings, numbers, true, false, null, objects and arrays. No undefined, NaN, Infinity or functions.
- Numbers have no leading zeros (007 is invalid) and no leading plus sign.
- Special characters inside strings must be escaped: ” for a quote, \ for a backslash, n for a newline.

Reading the error message
Parsers report where they gave up, which is often just after the real mistake. Different tools word it differently:
| Message | Usually means |
|---|---|
| Unexpected token } in JSON at position 52 | A trailing comma before the closing brace. |
| Unexpected token ‘ in JSON | Single quotes instead of double quotes. |
| Expected property name or ‘}’ | An unquoted key, or a trailing comma in an object. |
| Unexpected end of JSON input | The text was cut off: a missing closing bracket or brace. |
| Unexpected token u in JSON at position 0 | You parsed the string “undefined”, typically an empty variable in JavaScript. |
| Unexpected token < in JSON at position 0 | The server returned HTML (often an error page) instead of JSON. |
| Bad control character in string literal | A raw line break or tab inside a string; escape it as n or t. |
Paste the JSON into the JSON validator; it converts “position” into a line and column and highlights the spot.
The five fixes that solve most errors
1. Remove the trailing comma
{ "name": "WPDV", "tags": ["seo", "tools",] } ✗
{ "name": "WPDV", "tags": ["seo", "tools"] } ✓
2. Use double quotes everywhere
{ 'title': 'Hello' } ✗
{ "title": "Hello" } ✓
3. Quote every key
{ title: "Hello" } ✗ (valid JavaScript, invalid JSON)
{ "title": "Hello" } ✓
4. Escape quotes and backslashes inside strings
{ "html": "<a href="/">Home</a>" } ✗
{ "html": "<a href="/">Home</a>" } ✓
{ "path": "C:Usersme" } ✗
{ "path": "C:\Users\me" } ✓
5. Close every bracket
Count opening and closing braces and brackets, or format the JSON so the indentation shows where a block is not closed. The JSON formatter indents valid JSON and points at the line where structure breaks.
<h2
Invisible problems
- Smart quotes. Word processors and some chat apps turn ” into “ ”. Retype them in a code editor.
- A byte order mark (BOM) at the start of a file saved by some Windows editors. Save as “UTF-8 without BOM”.
- Non-breaking spaces copied from web pages. They look like spaces but are not whitespace to a JSON parser.
- Duplicate keys. Technically allowed by the spec, but most parsers silently keep only the last one, which causes confusing bugs.
When the JSON comes from a server
If JSON.parse fails on an API response, look at the raw response first (the Network tab in your browser’s developer tools). An HTML error page, a PHP warning printed before the JSON, or a redirect to a login page all produce “Unexpected token <“. Fix the server error rather than the parser.
In WordPress, a common cause is a plugin or theme printing a notice. Turn on WP_DEBUG_LOG and turn off WP_DEBUG_DISPLAY so warnings go to the log, not into REST and AJAX responses.
Need comments? Use another format
If a configuration file needs comments, JSON is the wrong tool. YAML supports comments and is easier to read, and many tools accept it. The YAML ⇄ JSON converter converts between the two, with line-numbered errors on both sides.
Checklist
- Double quotes only, on keys and strings.
- No trailing commas, no comments.
- Escape ” and \ inside strings.
- Every { and [ has a matching } and ].
- Check the raw response when parsing server output.
Related free tools for this topic
JSON Validator
Check whether JSON is valid and find the exact line and column of any syntax error.
Merge PDF Files Online (Free, No Uploads)
Combine multiple PDF documents into a single file directly in your browser. Reorder pages, keep your files private,…
Images to PDF Converter (JPG, PNG, WebP to PDF)
Turn screenshots, mockups, and loose images into one organized, properly sized PDF. Choose A4, US Letter, or fit…
Organise PDF: Reorder, Rotate & Extract Pages (Free)
Rearrange, rotate, delete or extract specific pages from any PDF document in your browser. Use visual page controls…
PDF to Images (JPG & PNG Converter)
Convert PDF pages into crisp PNG or JPEG images in your browser. Choose resolution scale (1× to 3×)…
SVG Optimiser for Web & Elementor (Clean viewBox & currentColor)
Shrink SVG icons, preserve the viewBox, remove fixed dimensions, and make vectors adapt to Elementor colours using currentColor.…
Related resources
SaaS hero with dashboard preview
Two-column hero: headline, supporting text, two buttons and a trust line beside a visual panel. Stacks to one…
Centred SaaS hero with product window
Centred hero with a large headline, supporting text and two buttons, with optional highlights and a product window…
Dark studio hero with service highlights
Centred hero with a large headline, supporting text and two buttons, with optional highlights and a product window…
More guides
How to Merge PDF Files Without Uploading Them
You don't have to hand contracts or invoices to an unknown server to combine them. Merge PDFs with Mac Preview or the…
Reorder, Rotate and Extract PDF Pages
Reordering, rotating, extracting and splitting each change a PDF differently. This guide explains when to use each, how to do it in…
URL Encoding: Which Characters Need Escaping and Why
Which characters must be percent-encoded in URLs, why spaces become %20 or +, and how to encode values correctly in JavaScript, PHP,…
Comments