formatjson.pro
Validate, pretty-print or minify JSON in your browser — nothing is uploaded.

SyntaxError: Unexpected token o in JSON at position 1

You called JSON.parse() on something that is already a JavaScript object. JavaScript coerces it to the string "[object Object]", and the parser trips on the 'o' at position 1. The fix is almost always to delete the JSON.parse() call — the value is already usable.

What the error means

JSON.parse() expects a string. When you hand it an object, JavaScript first converts the object to a string, which becomes the literal text [object Object]. Position 0 is [ (a valid array start), so the parser advances to position 1 and hits o — not valid there — and throws.

The usual cause

Your data was already parsed. A common pattern: const data = await res.json(); const obj = JSON.parse(data);. res.json() already returns an object, so the second parse is the bug.

Fix it

1. Remove the extra JSON.parse(). If the value is already an object, just use it: data.user.
2. If you truly need a JSON string, stringify instead: const s = JSON.stringify(obj); localStorage.setItem('x', s); then parse when reading it back.
3. Guard defensively: const obj = typeof v === 'string' ? JSON.parse(v) : v;

Nothing to repair in the payload itself — the bug is the extra parse call, not the data.

FAQ

Why 'o' and why position 1?

An object stringifies to "[object Object]". Position 0 is '[', which is a legal array opener, so the parser moves to position 1 and fails on the 'o'.

I get 'Unexpected token u' instead — same thing?

Yes, same class. 'u' comes from the string "undefined": you parsed an undefined value. Check that the variable actually holds data before parsing.

How do I know if I even need JSON.parse?

Log typeof value. If it is already 'object', do not parse. Only parse when typeof is 'string' and that string contains JSON text.