JSON troubleshooting guide
Fix unexpected token o in JSON at position 1
Unexpected token o at position 1 usually means JSON.parse received an object or [object Object] text instead of a valid JSON string.
Why this error usually appears
This error often happens when code calls JSON.parse on a value that is already a JavaScript object, or when an object has been converted to the string [object Object]. The parser reads the second character, sees the letter o, and fails because that is not valid JSON syntax.
Example
JSON.parse({
"status": "ok"
})
JSON.parse('{"status":"ok"}')
// Or use the object directly without parsing it again.
How to fix it
- Check the value before parsing it. If typeof value is object, do not pass it to JSON.parse.
- Only call JSON.parse when the input is a string that contains valid JSON, such as an API response body or a serialized payload.
- If the value is [object Object], find where the object was converted to text and serialize it with JSON.stringify when a JSON string is truly needed.
- Validate the final string as JSON before sending it to another API, storing it, or pasting it into a config field.
Check the type before parsing
The fastest way to debug this error is to inspect the value before the parse call. A real JSON string begins with characters such as {, [, quote, number, true, false, or null. A JavaScript object is already structured data and should be used directly.
In browser code, this is common after calling response.json. That method already parses the response body, so running JSON.parse on the returned object adds a second parsing step that the data does not need.
When stringifying is the right move
Use JSON.stringify when you need to store or transmit an object as JSON text. That creates a valid string with quoted keys, escaped characters, and nested values represented in JSON syntax.
Do not stringify just to parse again in the same place. Convert only at boundaries, such as localStorage, request bodies, queue messages, and plain text logs where another system expects JSON text.
Common mistakes
- Calling JSON.parse on an object that was already parsed by fetch response.json
- Saving an object into a text field without JSON.stringify
- Concatenating an object into a log message and then trying to parse the log output
- Assuming [object Object] is JSON because it came from a JavaScript object
Related problems
FAQ
Why does the error say token o?
The parser is usually reading [object Object]. The second character is o, which is not allowed at that point in valid JSON.
Should I use JSON.parse or JSON.stringify?
Use JSON.parse to turn a JSON string into data. Use JSON.stringify to turn data into a JSON string.
Can JSON Validator catch this problem?
Yes. Paste the string you plan to parse. If it is [object Object] or JavaScript object syntax, it will fail as invalid JSON.