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.

Runs entirely in your browser — no upload, no sign-up. It recognises the '[object Object]' pattern behind the token o error and points you at the double-stringify bug instead of a vague parse failure.

How to fix "Unexpected token o in JSON at position 1"

  1. Find the double JSON.parse or stringified object. The o comes from the word object: you called JSON.parse() on a value that is already a JavaScript object (which stringifies to "[object Object]"). Log typeof value — if it is 'object', it does not need parsing.
  2. Remove the redundant parse. If the value came from response.json(), axios, or another library, it is already parsed. Delete the extra JSON.parse() call and use the object directly.
  3. Stringify before storing, parse after reading. When persisting to localStorage or a cookie, JSON.stringify() on write and JSON.parse() on read — exactly once each. Paste a sample into the tool above to confirm it is valid JSON text.

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.