DoraPDF / Blog

How to Fix Common JSON Errors: Unexpected Token, Trailing Commas and Missing Quotes

By the DoraPDF team · 6 min read · Updated 2026-11-26
How to Fix Common JSON Errors: Unexpected Token, Trailing Commas and Missing Quotes

You paste a config file or an API response somewhere, and instead of working it throws "Unexpected token in JSON" at you. JSON is a small format with strict rules, and nearly every broken file breaks one of the same handful of rules. Once you know them, most errors take seconds to fix.

This guide lists the JSON errors people hit most often, what the error message usually looks like, and how to find and fix each one with the free JSON Validator on DoraPDF.

How to check a JSON file in your browser

  1. Open the JSON Validator.
  2. Paste your JSON into the input box.
  3. Pick an Output style: 2 spaces, 4 spaces, or Minify (everything on one line).
  4. The check runs live as you type or paste. If the JSON is valid you get a green Valid JSON status and the formatted result in the output box, ready to copy.
  5. If it is not valid, the status shows the error message from your browser's JSON parser. When the message includes a character position, the tool converts it into a line and column so you can jump straight to the problem.

The exact wording of the error depends on your browser, because the tool uses the browser's own JSON.parse. Chrome and Edge tend to say "Unexpected token" or "Expected ',' or '}'", Firefox says things like "expected double-quoted property name". The causes behind them are the same.

The eight JSON errors you will meet most

1. Trailing comma

JavaScript lets you leave a comma after the last item. JSON does not.

{ "name": "Ali", "age": 24, }

Remove the comma before } or ]. This is the single most common reason a hand-edited file stops working, especially after deleting the last line of a list.

2. Single quotes instead of double quotes

{ 'name': 'Sara' }

JSON only accepts double quotes, for both keys and string values. Replace every ' around keys and strings with ". If the text itself contains an apostrophe (like Sara's), that is fine inside double quotes.

3. Keys without quotes

{ name: "Sara" }

This is valid JavaScript but not valid JSON. Every key must be a quoted string: "name".

4. Missing comma between items

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

The parser reaches "b" while it is still waiting for a comma or a closing brace, so it complains about an unexpected string. The line and column point to the item after the missing comma, so look one step back.

5. Unclosed brackets or braces

A missing } or ] usually produces an "unexpected end of JSON input" style message, pointing at the very end of the text. Formatting helps here: once the parts that are valid are indented, a block that never closes stands out. Count opening and closing brackets in the section you last edited.

6. Comments

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

Standard JSON has no comments, neither // nor /* */. Some tools (VS Code settings, some config loaders) accept "JSON with comments", but a strict parser will reject it. Delete the comments, or move the note into a real field like "_note": "...".

7. Wrong values: NaN, undefined, True

JSON values can only be strings, numbers, true, false, null, objects and arrays. undefined, NaN, Infinity, Python-style True/None and dates written without quotes are all invalid. Use null for missing values and put dates in a string such as "2026-11-26".

8. Unescaped characters inside strings

A raw line break or tab inside a string, or a double quote that is not escaped, ends the string early. Write \n for a new line, \t for a tab and \" for a quote. Windows file paths are a classic trap: "C:\\Users\\Ali" needs doubled backslashes.

"Unexpected token" at position 0

If the error points at the very first character, the problem is usually not your JSON at all:

A quick fixing routine

When a big file fails, work like this rather than reading it top to bottom:

  1. Run it through the validator and note the line and column.
  2. Look at that spot and the line just before it. Missing commas and unclosed strings are reported where the parser notices the damage, not where it started.
  3. Fix one thing, run again. Often one mistake causes the error, and fixing it reveals the next one.
  4. Once it is valid, choose 2 spaces to get a readable version for review, or Minify to make it compact for sending or embedding.

If your data started life as a spreadsheet, it can be easier to regenerate the JSON than to repair it. Export the sheet as CSV and use the CSV to JSON Converter. It reads the header row as keys, handles quoted fields, turns plain numbers into JSON numbers and lets you pick comma, semicolon or tab as the separator. It also works the other way round, JSON to CSV, when you need to open data in Excel.

Tips to avoid JSON errors in the first place

Privacy

The JSON Validator and the CSV to JSON Converter run entirely in your browser. The text you paste is parsed on your own device and is not uploaded to DoraPDF, so you can safely check API responses or config files that contain internal data. Still, avoid pasting live passwords or keys anywhere you do not need to.

FAQ

Why does the validator say my JSON is invalid when my code accepts it? Some tools are lenient and accept comments, trailing commas or single quotes. The validator follows strict JSON, which is what most APIs and parsers expect.

What does "Unexpected end of JSON input" mean? The text stopped before everything was closed: usually a missing } or ], or a string that never got its closing quote.

Can I minify JSON with this tool? Yes. Choose Minify as the output and valid JSON is returned on a single line without spaces.

Does formatting change my data? No. Formatting only changes whitespace. Keys, values and their order stay the same.

Is there a size limit? There is no fixed limit; the only limit is your device's memory. Very large files may make the page slow while it formats them.

Try the tools from this guide — free

Keep reading

Guide

Free Developer Tools Online: JSON Formatter, Regex Tester, Base64, URL Encoder, JWT Decoder, SQL and UUID

Eight small browser-based developer tools for everyday debugging: validate JSON, test regex, decode JWTs and Base64, format SQL, make UUIDs. Free.

Guide

How to Extract Tables from a PDF to Excel or CSV

Extract tables from a PDF into Excel or CSV for free: convert, merge tables across pages, fix split columns and turn the data into JSON if you need it.

Guide

Hotel Website Template: Build a Resort or Travel Site With the Kage 3D Theme

Plan a hotel, resort or travel agency website and build it with Kage, a 3D scroll theme with rooms, gallery, reviews and a WhatsApp button.