JSON is strict. A config file, an API response or a data export can look perfectly fine and still be rejected with "Unexpected token" or "Expected property name". The cause is almost always one of a handful of small mistakes, usually something that is allowed in JavaScript but not in JSON.
This guide lists those mistakes, shows how to find the exact spot quickly, and explains how to keep the file valid once it is fixed.
Find the error in seconds
Paste the JSON
Paste it into JSON Formatter. It checks the text as you type or paste, in your browser.
Read the line and column
If the JSON is invalid, the formatter shows the error message with the line and column where parsing failed. The real mistake is usually at that spot or just before it.
Fix and format
Correct the mistake, then format the result with 2 spaces, 4 spaces or tabs. Proper indentation makes the next problem, if there is one, easy to see.
The usual suspects
These cause the vast majority of invalid JSON:
- A trailing comma after the last item in an object or array, such as [1, 2, 3,]. JavaScript allows it; JSON does not.
- Single quotes. JSON strings and keys must use double quotes, so {'name': 'Ana'} is invalid and {"name": "Ana"} is valid.
- Keys without quotes, such as {name: "Ana"}. Every key must be a quoted string.
- Comments. JSON has no // or /* */ comments, so remove them or move them into a separate field.
- Curly quotes pasted from a word processor or chat app instead of straight double quotes.
- Values JSON does not know: undefined, NaN, Infinity, or dates written without quotes. Use null, a number, or a quoted string instead.
- A missing comma between two items, which usually shows up as an error at the start of the second item.
- Two separate JSON objects one after the other without being wrapped in an array.
Reading the error message
Browsers phrase errors differently, but they point at the same thing. "Unexpected token" means the parser met a character it did not expect at that position, such as a quote of the wrong kind or a stray comma. "Unexpected end of JSON input" means something was opened and never closed: a missing closing brace, bracket or quote, often caused by a file that was cut off while copying or downloading. "Expected property name" usually means a trailing comma or an unquoted key inside an object.
Keep it valid
Once the JSON parses, format it consistently and, if the order of keys does not matter, use Sort Keys so that two versions can be compared line by line. The tree view is handy for checking the structure of a large response without scrolling through it. When you need the data in a spreadsheet rather than in code, convert it to CSV; the JSON to Excel guide shows how to open the result cleanly.
Frequently asked questions
Is my JSON sent anywhere?
No. JSON Formatter parses and formats the text in your browser, so API keys or customer data in the JSON never leave your device.
Why does my JSON work in JavaScript but fail as JSON?
JavaScript object literals allow single quotes, unquoted keys, trailing commas and comments. JSON allows none of them, so code that runs fine can still be invalid JSON.
Can JSON have comments?
Standard JSON cannot. Some tools accept variants with comments, but most parsers reject them, so remove comments from files that other programs read.
How do I make JSON smaller?
Use the minify option, which removes all spaces and line breaks without changing the data.
More guides
How to Reduce PDF File Size for Email
PDF too big to email? Learn why PDFs get large and how to shrink them under Gmail and Outlook attachment limits, free and without installing anything.
How to Sign a PDF on Your iPhone or Android Phone
Sign a PDF on your phone in about a minute: draw your signature with a finger, place it, add the date and download. Free, no app to install, no signup needed.
How to Turn Photos of Documents into One PDF
Scanned or photographed pages everywhere? Turn phone photos of documents into one clean, correctly ordered PDF that is small enough to email. Free, no signup.
How to Convert a PDF to an Editable Word Document
Convert a PDF into an editable Word file, know when conversion works well, and what to do with scanned PDFs. Free, no signup, and your file is deleted after.