The json parse unexpected token o syntax error is incredibly frustrating because, at first glance, your code looks perfectly fine. You are almost certainly trying to parse an object, so why is the JavaScript engine complaining about the letter “o”?
Why the Letter “o”?
This error occurs exclusively because you are trying to use JSON.parse() on something that is already a JavaScript Object, rather than a JSON string.
When you pass a raw Object (like { id: 1 }) into JSON.parse(), the parser expects a string. Because it doesn’t get a string, it implicitly calls the .toString() method on your object.
- The string representation of any plain JS object is:
"[object Object]" - The
JSON.parse()engine starts reading that new string from left to right. - Position 0 is the
[bracket. This is a valid JSON array start. - Position 1 is the letter
o(from the word “object”). - The English letter “o” is not a valid JSON character here, so it immediately crashes with: unexpected token o in JSON at position 1.
Want a comprehensive breakdown of all token errors (like ‘u’, ’<’, or ‘DOCTYPE’)? Check out our flagship Ultimate Unexpected Token Guide.
The Fix: Stop Double Parsing
The solution is entirely dependent on removing the redundant JSON.parse() call. If you are receiving a payload and aren’t sure if it has already been parsed by a library (like Axios or Next.js fetch), you can add a generic type check.
For the fastest debugging, simply output the raw payload and paste it into our Secure JSON Formatter tool—if the tool says the payload is invalid, you actually received a bad string.
// The fix: Only parse if the payload is actually a string
function safeParse(data) {
if (typeof data === 'string') {
return JSON.parse(data);
}
// It's already an object! Just return it.
return data;
}
Related JSON Errors
If fixing the double parse unexpectedly triggers a new error where quotes look messed up (e.g., \"), you are likely dealing with escaped strings sent from a bad database script. Learn how to clean these up in our Guide to Unescaping JSON.
Alternatively, if your payload ends prematurely, you are encountering a network-level fetch issue, which you can resolve by following How to fix fetch unexpected end of JSON input.