What "Unexpected token in JSON at position X" means
JSON parsers read your text one character at a time. When they reach a character that cannot appear at that point in valid JSON, they stop and report it. The "token" is that character, and the "position" is how many characters came before it, counting from 0, including spaces and line breaks. So Unexpected token } in JSON at position 88 means "character number 88 (the 89th) is a }, and a } is not allowed there".
The character that is reported is where the parser noticed the problem, which is often just after the real mistake. A } is rejected because of the comma before it; a " is rejected because the comma that should come before it is missing. Look at the reported character and the one or two tokens before it.
The box above does this for you. It shows the line, column and position of the first error with a caret under it, your browser's own JSON.parse message for comparison, and a hint. Paste the position from your error message into the converter below the box to jump to the same spot in your text.
Old and new wording: "Unexpected token" vs "is not valid JSON"
The message depends on the JavaScript engine. Older Chrome and Node.js (Node 18 and earlier) said Unexpected token X in JSON at position N for almost everything. Current V8, used by Chrome, Edge and Node.js 20+, gives a more specific message, quotes the start of the input, and recent versions also add (line L column C). Searching for either wording leads to the same causes:
| Input | Older V8 (Node 18, older Chrome) | Current V8 (Node 20+, Chrome, Edge) |
|---|---|---|
{"a":1,} | Unexpected token } in JSON at position 7 | Expected double-quoted property name in JSON at position 7 |
[1,2,] | Unexpected token ] in JSON at position 5 | Unexpected token ']', "[1,2,]" is not valid JSON |
[object Object] | Unexpected token o in JSON at position 1 | "[object Object]" is not valid JSON |
<!DOCTYPE html> | Unexpected token < in JSON at position 0 | Unexpected token '<', "<!DOCTYPE "... is not valid JSON |
undefined | Unexpected token u in JSON at position 0 | "undefined" is not valid JSON |
{'a':1} | Unexpected token ' in JSON at position 1 | Expected property name or '}' in JSON at position 1 |
{"a":1 "b":2} | Unexpected string in JSON at position 7 | Expected ',' or '}' after property value in JSON at position 7 |
{"a":1}x | Unexpected token x in JSON at position 7 | Unexpected non-whitespace character after JSON at position 7 |
Unexpected token } in JSON at position N
Almost always a trailing comma: a comma after the last property, right before the closing brace. JavaScript accepts it, JSON does not. Current V8 reports the same input as Expected double-quoted property name, because after a comma it expects another "key".
{ "id": 1024, "price": 39.5, } ← invalid
{ "id": 1024, "price": 39.5 } ← valid
The same mistake in an array gives Unexpected token ]. Delete the comma, or click Repair JSON. More detail, including why JSON forbids it, is in the JSON trailing comma guide.
Unexpected token o in JSON at position 1
You passed a JavaScript object to JSON.parse. It converts its argument to a string first, and String({}) is "[object Object]". Position 0 is [, which is fine, and position 1 is the letter o, which is not. The usual causes:
- Parsing data that is already parsed:
JSON.parse(response.data)with axios, orJSON.parse(await res.json())with fetch. Both give you an object already. - Saving an object to
localStoragewithoutJSON.stringify, which stores the literal text[object Object]. - Building a request body with string concatenation, such as
"data=" + obj.
const data = typeof body === 'string' ? JSON.parse(body) : body; // parse only strings
localStorage.setItem('cart', JSON.stringify(cart)); // store JSON text, not the object
If you need to turn a JavaScript object literal into JSON text, see JavaScript object to JSON.
Unexpected token < in JSON at position 0
The response is HTML, not JSON. The first character of an HTML page is < from <!DOCTYPE html> or <html>. The server (or something in between) returned a web page: a 404 or 500 error page, a login or SSO redirect, a CDN or proxy error, or a single-page-app dev server answering an unknown /api path with index.html. In PHP apps, a warning printed before the JSON produces <br /> at position 0 for the same reason.
Do not try to repair it. Check the response before parsing and log what actually came back:
const res = await fetch('/api/items');
const type = res.headers.get('content-type') || '';
if (!res.ok || !type.includes('application/json')) {
const text = await res.text();
throw new Error('Expected JSON, got ' + res.status + ' ' + type + ': ' + text.slice(0, 200));
}
const items = await res.json();
Then open the URL in the browser's Network tab. A wrong path, a missing proxy rule, an expired session cookie or a server crash will be obvious from the HTML.
Unexpected token u in JSON at position 0
JSON.parse(undefined) turns undefined into the string "undefined" and fails on the u. Current V8 says "undefined" is not valid JSON. The variable you are parsing was never set: a property name typo, a function that forgot to return, a missing environment variable, or an API field that is absent. Note that JSON.parse(null) does not throw (it returns null), so a missing localStorage key is not this error, but localStorage.getItem('x') || undefined would be.
const raw = process.env.APP_CONFIG;
const config = raw ? JSON.parse(raw) : {};
Unexpected token ' in JSON at position 1
The JSON uses single quotes. JSON strings and keys must use double quotes. Current V8 reports Expected property name or '}' in JSON at position 1. This typically comes from Python's print(dict) or str(dict), or from JSON typed by hand. Repair converts the quotes; the root fix is to emit real JSON, for example json.dumps(data) in Python. See JSON single quotes and Python dict to JSON.
Unexpected token in JSON at position 0 with an invisible character (BOM)
If the message shows a token you cannot see, the file probably starts with a UTF-8 byte-order mark (U+FEFF), added by some Windows editors and by PowerShell's older Out-File. Current V8 prints Unexpected token '', "{...}" is not valid JSON with an invisible first character, and Python says Unexpected UTF-8 BOM (decode using utf-8-sig). Strip it before parsing, or click Repair JSON above:
// Node.js
const data = JSON.parse(fs.readFileSync('data.json', 'utf8').replace(/^/, ''));
# Python
data = json.load(open('data.json', encoding='utf-8-sig'))
Other invisible troublemakers are non-breaking spaces and zero-width spaces pasted from chat apps or web pages. The strict check above names them by code point.
How to convert "position N" to line and column
Position is a zero-based index into the string, counted in UTF-16 code units, which is exactly the index JavaScript uses for text[N]. Line breaks count as one character each (\r\n counts as two). To find the line and column yourself:
function lineCol(text, pos) {
const before = text.slice(0, pos).split('\n');
return { line: before.length, column: before[before.length - 1].length + 1 };
}
lineCol(text, 88); // default example above: { line: 6, column: 1 }
Or paste the number (or the whole error message) into the Position to line and column box above; it uses whatever text is in the editor. Python's (char N) is the same zero-based index, but Python already prints the line and column for you. If the position is past the end of your text, you are looking at a different string from the one that failed. Log the exact value you passed to JSON.parse.
The same error in other languages
Every JSON parser rejects the same inputs, but the messages differ. These are the messages for the two most common causes: an HTML page, and single-quoted keys ({'a':1}):
| Language / parser | HTML instead of JSON | Single-quoted key |
|---|---|---|
| JavaScript (V8: Chrome, Node.js) | Unexpected token '<', "<!DOCTYPE "... is not valid JSON | Expected property name or '}' in JSON at position 1 |
| Firefox | JSON.parse: unexpected character at line 1 column 1 of the JSON data | JSON.parse: expected property name or '}' at line 1 column 2 of the JSON data |
Python json | Expecting value: line 1 column 1 (char 0) | Expecting property name enclosed in double quotes: line 1 column 2 (char 1) |
Go encoding/json | invalid character '<' looking for beginning of value | invalid character '\'' looking for beginning of object key string |
| Java (Jackson) | Unexpected character ('<' (code 60)): expected a valid value (JSON String, Number, Array, Object or token 'null', 'true' or 'false') | Unexpected character (''' (code 39)): was expecting double-quote to start field name |
PHP json_last_error_msg() | Syntax error | Syntax error |
Python's requests raises the same Expecting value: line 1 column 1 (char 0) from response.json() when the server sends HTML or an empty body.
Quick checklist
- Log the exact string you pass to
JSON.parse, itstypeof, and its length. - If it is not a string, do not parse it: it is already an object (the "token o" case) or undefined (the "token u" case).
- If it starts with
<, fix the request or the server, not the JSON. - Otherwise, paste it above. Find the error pinpoints the character; Repair JSON fixes the common mistakes and tells you what it changed. Large numbers such as 64-bit IDs are kept exactly (see JSON big integer precision).
Frequently asked questions
What does "Unexpected token in JSON at position X" mean?
The JSON parser found a character that is not allowed at that point. The token is that character and the position is its zero-based index in the string. The real mistake is usually at or just before that character, for example a trailing comma before a closing brace.
How do I find position X in my JSON?
Paste the JSON into the box on this page and click Find the error to get the line and column with a caret. Or enter the position in the Position to line and column box. In code, count the line breaks in text.slice(0, X): the line is that count plus one.
Why do I get "Unexpected token < in JSON at position 0"?
The response is an HTML page, not JSON. It is usually a 404 or 500 error page, a login redirect, or a dev server returning index.html for an unknown API path. Check response.ok and the Content-Type header before calling res.json(), and log the start of the body.
Why do I get "Unexpected token o in JSON at position 1"?
You called JSON.parse on a JavaScript object. It was converted to the string "[object Object]", and the o at position 1 is invalid. The data is already parsed, so use it directly. This is common with axios response.data and with values saved to localStorage without JSON.stringify.
Why does Chrome say "is not valid JSON" instead of "Unexpected token"?
Newer versions of the V8 engine, used by Chrome, Edge and Node.js 20 and later, rewrote the JSON.parse error messages. They quote the start of the input and give more specific reasons, such as Expected double-quoted property name. The causes and fixes are the same.
Can this tool fix the error automatically?
For syntax mistakes, yes. Repair JSON removes trailing commas and comments, converts single quotes, quotes unquoted keys, strips a byte-order mark and closes truncated brackets, then lists each fix. It refuses to repair HTML, [object Object] and undefined, because those are not JSON and need a code fix.
Is my JSON sent to a server?
No. Checking and repairing run in JavaScript in your browser, so you can paste API responses that contain tokens or customer data.