How to Fix Invalid JSON
JSON syntax errors are frustrating but almost always simple to fix once you know what to look for. Paste your JSON below to repair it in one click, then read on for the 8 most common reasons JSON fails to parse, with exact before/after examples for each one.
Repairs trailing commas, single quotes, unquoted keys, comments, Python's None/True/False, NaN, smart quotes, JSONP wrappers, missing commas and unclosed brackets. Text inside strings is never touched. Everything runs in your browser.
{
'name': 'Alice',
age: 30,
"city": "New York",
}Step 1 — Find the Error Line
Before fixing, you need to know where the error is. Paste your JSON into the JSON Validator — it reports the exact line and character position of the first syntax error.
Note: JSON parsers stop at the first error. Fix one error, re-validate, and repeat until the document is clean. There may be multiple errors hidden behind the first one.
The 8 Most Common JSON Errors
These errors account for over 95% of all JSON validation failures:
JSON requires double quotes for all strings and keys. Single quotes are valid JavaScript but not valid JSON.
{'name': 'Alice'}{"name": "Alice"}Remove the comma after the last item in an object or array. Most editors can detect this with a JSON linter.
{"a": 1, "b": 2,}{"a": 1, "b": 2}Every key in a JSON object must be wrapped in double quotes. JavaScript objects allow unquoted keys — JSON does not.
{name: "Alice", age: 30}{"name": "Alice", "age": 30}JSON does not support comments of any kind — neither // nor /* */. Remove all comments before parsing.
{"key": "value" // a comment}{"key": "value"}JSON has no undefined or NaN. Replace them with null, or omit the key entirely if the value is not applicable.
{"score": NaN, "result": undefined}{"score": null, "result": null}Each key-value pair in an object and each element in an array must be separated by a comma.
{"a": 1 "b": 2}{"a": 1, "b": 2}Every opening bracket [ and brace { must have a matching closing bracket ] and brace }. Use a beautifier to reveal the nesting structure.
{"users": [{"id": 1}{"users": [{"id": 1}]}Numbers should be unquoted (42) and strings should be quoted ("99"). Mixing them causes type errors in most parsers.
{"count": "42", "label": 99}{"count": 42, "label": "99"}Common JSON Error Messages, Decoded
If you landed here by pasting an exact error message into search, here's what each one means and how to fix it:
invalid input syntax for type jsonPostgreSQLWhat it means: Postgres throws this when inserting or casting a value into a json or jsonb column and the text isn't valid JSON — often a trailing comma, single quotes, or a plain string passed where JSON was expected.
Fix: Validate the string with a JSON validator before the INSERT or UPDATE. If you're building the JSON in application code, use JSON.stringify() (or your language's equivalent) instead of concatenating strings — hand-built strings are the most common cause.
Unexpected end of JSON inputJavaScript — JSON.parse()What it means: The string passed to JSON.parse() was empty or got cut off partway through — usually a network response that failed, timed out, or was truncated before all the data arrived.
Fix: Log the raw string before parsing to confirm it isn't empty ("") or truncated. If it's an API response, check the request actually completed — a fetch body stream can only be read once.
"undefined" is not valid JSONJavaScript — JSON.parse()What it means: Something passed the literal string "undefined" to JSON.parse() — usually the result of reading a value that doesn't exist, like localStorage.getItem() returning null and later being coerced to text.
Fix: Check for null before parsing: const raw = localStorage.getItem('key'); if (raw) JSON.parse(raw). Never call JSON.parse() on a value that might be undefined.
Lexical error: invalid char in JSON textStrict parsers (e.g. Java's org.json)What it means: The JSON contains a raw control character — most often a literal newline or tab typed directly inside a quoted string instead of being escaped.
Fix: Escape control characters inside strings — use \n for a newline and \t for a tab, never the literal character. Run the JSON through a validator to see the exact line and character.
0x0A is invalid within a JSON stringVarious strict parsersWhat it means: 0x0A is the hex code for a newline character. A raw line break was found inside a quoted string — the JSON spec requires it to be escaped.
Fix: Find the string containing the line break and replace it with an escaped \n. This is common when JSON is generated from user-submitted multi-line text without proper escaping.
Tips to Prevent JSON Errors
Validate and Fix Your JSON Now
Paste your JSON and get the exact error line instantly — free, no sign-up.
Open JSON Validator