Fix “Unexpected token o in JSON at position 1”

Why JSON.parse throws “unexpected token o at position 1”, how to confirm the cause, and how to fix it without hiding the real bug.

The error “Unexpected token o in JSON at position 1” almost always means JSON.parse was given something that is not a JSON string, most often a JavaScript object that has already been parsed. This guide explains where the stray “o” comes from, how to confirm which situation you are in, and how to fix it at the source instead of suppressing the error.

Should you be calling JSON.parse here?

Short answer: only if the value is a string that contains JSON text. JSON.parse turns JSON text into a JavaScript value, and JSON.stringify does the reverse. That conversion is useful at boundaries: reading a network response body as text, reading from storage that only holds strings, or loading a file. Inside your code, once a value is already an object, parsing it again adds nothing and causes this error.

The tradeoff is where you keep the data as text and where you keep it as an object. Keep it as plain JSON text when it is stored, transmitted or pasted into a validator or formatter. Keep it as an object while your code is working with it. Most occurrences of this error come from losing track of which form a value is in.

What actually goes wrong

JSON.parse expects a string. If you pass it something else, JavaScript first converts the argument to a string. A plain object converts to the literal text “[object Object]”. The parser reads that text from the start: position 0 is “[”, which is a valid way to begin a JSON array, and position 1 is “o”, which is not a valid value. Parsing stops there, which is why the error names the token “o” at position 1. Positions are counted from zero.

const data = { name: "Ada" };
JSON.parse(data);
// data is converted to the string "[object Object]"
// index 0 is "[" (allowed), index 1 is "o" (not allowed) -> error

So the “o” does not come from your data. It comes from the word “object” in JavaScript’s default string conversion. The message text also varies by engine and version. Newer Chromium and Node.js builds use a format like “Unexpected token 'o', "[object Obj"... is not valid JSON”. Firefox reports an unexpected character at line 1 column 2. These all describe the same failure. The exact wording in your environment was not verified for this article.

The browser console can hide the problem. Logging an object and logging a JSON string can look similar, but only the string is text. Chromium’s console, for example, shows object keys without quotes, so console output copied from an object is often not valid JSON either.

Common causes and how to tell them apart

Situation | What JSON.parse receives | Typical position in the error
Value already parsed (double parse) | An object, converted to "[object Object]" | o at position 1
Object stored without JSON.stringify, then read back | The string "[object Object]" | o at position 1
Value is undefined | Converted to "undefined" | u at position 0
Server returned an HTML page instead of JSON | Text starting with "<" | < at position 0

The last two rows are different errors, included only because they are easy to confuse with this one. If your message says “o” at position 1, focus on the first two rows.

Check 1: what type is the value?

console.log(typeof value, value);
// "object" -> already parsed; remove the JSON.parse call
// "string" -> inspect the text; "[object Object]" means it was
//             converted to a string earlier, before it was saved or sent

If the type is “object”, you have a double parse. If the type is “string” and the content is literally “[object Object]”, the damage happened earlier, when an object was written somewhere that only stores text. Removing JSON.parse will not help in that case, because the original data is already gone from that stored value.

Cause A: parsing a response that is already parsed

The Fetch API’s response.json() reads the body and returns a parsed value, not a string. Several HTTP client libraries also parse JSON responses automatically by default. Axios is a well-known example; its response.data is usually an object already. Check your library’s documentation for its default behavior instead of assuming.

const res = await fetch(endpoint);
const user = await res.json();   // already a JavaScript object
JSON.parse(user);                // throws: user is not a string

// Fix: use the parsed value directly
console.log(user.name);

If you need the raw text, for example to log it or to show it in a formatter, call response.text() instead of response.json(). Then call JSON.parse on that text yourself.

Cause B: storing an object without stringifying it

Web Storage (localStorage and sessionStorage) stores only strings. Passing an object converts it to “[object Object]”, and the next JSON.parse on that stored value fails with this error.

// Wrong: stores the text "[object Object]"
localStorage.setItem("settings", settings);

// Right: store JSON text, parse it when reading
localStorage.setItem("settings", JSON.stringify(settings));
const restored = JSON.parse(localStorage.getItem("settings"));

After you fix the write side, values saved before the fix are still corrupted. Remove or overwrite them, for example with localStorage.removeItem("settings") or by clearing site data, so existing users do not keep hitting the error.

Cause C: string concatenation or template literals

Building a request body or message with “+” or a template literal converts embedded objects the same way. If you see “[object Object]” inside text you are sending, wrap the object in JSON.stringify before inserting it, or send JSON.stringify of the whole payload.

Should you add a defensive guard?

A small helper can accept either form:

function toObject(value) {
  return typeof value === "string" ? JSON.parse(value) : value;
}

Use this with care. It removes the double-parse symptom, but it can hide the fact that different code paths hand you different types. It also does nothing for the stored-string case, because “[object Object]” is a string and will still fail. Fix the source first. Keep a guard like this only at a boundary where mixed input is genuinely expected, and add a try/catch there if invalid text is possible.

Getting readable JSON you can copy, share or validate

To paste data into a JSON validator or formatter, or to share it in a bug report, convert it to real JSON text first instead of copying console output:

console.log(JSON.stringify(value, null, 2));

The extra arguments add two-space indentation, which makes the text easier to read and to compare line by line. Keep these limits in mind:

  • JSON.stringify drops functions and undefined properties and converts Date objects to strings, so the text may not match the in-memory object exactly.
  • Circular references cause JSON.stringify to throw a separate error.
  • Pasting the literal text “[object Object]” into any validator fails, because no data survived the earlier conversion.

Quick fix checklist

  • Log typeof value just before the JSON.parse call.
  • If it is an object, delete the extra JSON.parse.
  • If it is the string “[object Object]”, find where it was written and add JSON.stringify there, then clear the bad stored values.
  • If the error shows a different token or position 0, check for undefined input or an HTML response instead.
  • Use JSON.stringify(value, null, 2) when you need shareable, valid JSON text.

Limits of this guide

The explanations above follow documented JavaScript behavior for string conversion, JSON.parse, the Fetch API and Web Storage. No environment-specific tests were run for this article. Exact error wording, console display and HTTP library defaults vary by engine, version and configuration, so confirm them against your own runtime and your library’s documentation.