For the life of me I am don’t know why I get the following error when converting the below string to JSON using JSON.parse.
var parameters = {
“body”: {
“fromICAO”: “DAUE”,
“toICAO”: “EDDM”
},
“headers”: {
“Authorization”: “XXX”,
“Content-Type”: “application/json”
},
“method”: “post”
}
parameters = JSON.parse(parameters)
Error: Unexpected token o in JSON at position 1
Anyone have a clue?
J.D
March 15, 2021, 4:11pm
2
The parameters are already parsed (it’s a regular object). You can’t re-parse it.
That is what I thought. I am sending this to an API and that is the message they return to me as an error. I added the JSON.parse and see that is the same error. I imagine the API needs it in text. How do I convert that value to string then?
yeah. I thought so too but then I get an error from the api. I will contact the API owner. thanks
Just a thought. If you JSON.stringify, you will get, by default, a leading \ before every string. .stringify has a provision for it to not send that.
I think he needs to stringify it instead.