FormatWell

Guides / JSON errors

Unexpected token o in JSON at position 1

How it appears per engine

  • Uncaught SyntaxError: Unexpected token o in JSON at position 1 (older Chrome / Node.js)
  • Unexpected token 'o', "[object Object]" is not valid JSON (newer Chrome / Node.js)

What this error means

JSON.parse expects a string. If you pass it a JavaScript object, the object is coerced to the string "[object Object]" first — and the “o” at position 1 is the second character of that string. In other words: the data was already parsed, and you parsed it twice.

Common causes

1. The value was already an object

Libraries like axios parse JSON for you (response.data is an object). Calling JSON.parse on it coerces the object to "[object Object]" and throws.

Fails

const res = await axios.get(url);
const data = JSON.parse(res.data); // res.data is ALREADY an object

Works

const res = await axios.get(url);
const data = res.data; // nothing to parse

2. You stored an object without stringifying it

localStorage.setItem coerces values to strings. Storing an object directly saves the literal text "[object Object]", which can never be parsed back.

Fails

localStorage.setItem('user', user); // saves "[object Object]"

Works

localStorage.setItem('user', JSON.stringify(user));
const user = JSON.parse(localStorage.getItem('user') ?? 'null');

How to fix it

  1. Check the type first: only parse when typeof value === "string".
  2. Find the double-parse: if the value came from res.json(), axios, or a message handler, it is already an object.
  3. When storing, always JSON.stringify; when reading, always JSON.parse — never mix the two conventions.

Related errors