Hi,
I'm connecting to the api with angular. It returns 200 as a result. But I am getting the following error. Why does this problem occur? What is the solution. Can you help me.
Error : unexpected token o in json at position 0 at json.parse
Hi,
I'm connecting to the api with angular. It returns 200 as a result. But I am getting the following error. Why does this problem occur? What is the solution. Can you help me.
Error : unexpected token o in json at position 0 at json.parse
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Lakshna S39 reputationPosted Dec 6, 2021, 5:14 AM EST
This error occurs when you parse some data where parsing is not required. The error means no parsing is required.
You can test this yourself, e.g. in Chrome's console:
new Object().toString() // "[object Object]" JSON.parse(new Object()) // Uncaught SyntaxError: Unexpected token o in JSON at position 1JSON.parse()converts the input into a string.The
toString()method of JavaScript objects by default returns[object Object], resulting in the observed behavior.Solution: Remove the parsing.