JSON Errors / JavaScript

Unexpected token 'o', "[object Object]" is not valid JSON

How to Fix: Unexpected token 'o', "[object Object]" is not valid JSON

You passed a JavaScript object - not a string - to JSON.parse(). The parser coerces its argument to a string, an object becomes the literal text "[object Object]", and parsing fails at the "o" (position 1, right after "[").

The fix is never about the data itself: either the value was already parsed (so parsing again is unnecessary), or you meant to call JSON.stringify() instead.

{"find": "error"}paste your JSON below

Common causes

1. Double-parsing an already-parsed value

response.json() and most HTTP libraries (like axios) return already-parsed objects. Calling JSON.parse() on that result coerces the object back to "[object Object]".

Invalid
const data = await res.json();
const parsed = JSON.parse(data); // data is already an object!
Valid
const data = await res.json(); // done - it is already parsed

2. Storing an object in localStorage without stringifying

localStorage only stores strings. Setting an object directly stores "[object Object]", which then fails to parse when read back.

Invalid
localStorage.setItem("user", user);        // stores "[object Object]"
Valid
localStorage.setItem("user", JSON.stringify(user));
const user = JSON.parse(localStorage.getItem("user"));

3. Mixing up parse and stringify

Calling JSON.parse() when you meant JSON.stringify() - parse goes string → object; stringify goes object → string.

How to fix it

Check the type before parsing (JavaScript)
const value = maybeStringOrObject;
const data = typeof value === "string" ? JSON.parse(value) : value;
Correct localStorage round-trip
// write
localStorage.setItem("settings", JSON.stringify(settings));
// read
const settings = JSON.parse(localStorage.getItem("settings") ?? "{}");

Frequently asked questions

Why position 1 and the letter "o"?

The coerced string is "[object Object]". Position 0 is "[", which is valid (it could start an array). Position 1 is "o", which is invalid inside an array context - so the parser reports the "o" at position 1.

How do I know if my variable is already parsed?

Log typeof value. If it is "object", it is already parsed - use it directly. If it is "string", it still needs JSON.parse(). Modern fetch/axios responses are objects; raw WebSocket messages and localStorage values are strings.

I see this with axios - why?

axios parses JSON automatically: response.data is already an object. Calling JSON.parse(response.data) double-parses it. Use response.data directly.

Last updated:

Related JSON errors

You might also need

Free and in-browser, like everything on JSON Console. Browse all tools →