All Recipes
StarVerified Developer Solution • 100% Offline
JSON Formatter & Validator

Fix "SyntaxError: Unexpected token o in JSON at position 1"

Understand and fix the common JavaScript error when calling JSON.parse() on an object instead of a string.

The Problem (Error Root Cause)Exception

You are seeing `SyntaxError: Unexpected token o in JSON at position 1`. This happens when you call `JSON.parse()` on something that is already a JavaScript object (which gets coerced to the string `"[object Object]"`).

Identified via runtime validation & stack traces
The Solution (Step-by-Step Fix)Verified

Check if your data is already parsed. If you are using `axios` or `fetch` with `.json()`, the response is already an object. Only use `JSON.parse()` on raw string data.

Deterministic, non-destructive resolution

Code Standard: Bad Pattern vs Verified Fix

Live Syntax
Anti-Pattern vs Verified Fix
1// ❌ Bad: Parsing an already parsed object
2const data = { name: "John" };
3const parsed = JSON.parse(data); // Unexpected token o
4
5// ✅ Good: Check type or rely on fetch's built-in parsing
6const res = await fetch('/api/data');
7const json = await res.json(); // json is already an object!

Test and resolve this using JSON Formatter & Validator

Execute directly in your browser memory. Zero API keys, zero network tracking, completely client-side.

Launch JSON Formatter & Validator

Frequently Asked Questions

Q:Why does it say position 1?

Because it converts the object to the string "[object Object]". The first character is "[", the second (position 1) is "o". JSON expects quotes.

Q:How can I validate my JSON string?

Use our JSON Formatter to paste your string and ensure it is valid JSON before parsing.

Related Troubleshooting Guides

View Directory