Jo Micheal
Published in : 2022-01-30
I am trying to use JSON.parse() to convert the text of JSON to objects but when I run the code I get this error
SyntaxError: Unexpected token o in JSON at position 1
The JSON example which I am using is
jQuery(document).ready(($) => { //Create variable to store the JSON var data = [ { "id": 3, "title": "Lets narrow down your selection", "subtitle": "What services do you want to include in your selection?", "answers":[ { "name": "Driver Profiling", "value": "0" }, { "name": "Driver Assessment", "value": "1" }, { "name": "Driver Training", "value": "2" }, { "name": "Driver Management", "value": "3" }, { "name": "Driver License check", "value": "4" }, ] }, ]; let test = JSON.parse(data); console.log(test);});
What should I do?
Join our community and get the chance to solve your code issues & share your opinion with us
Sign up Now
Mohamed Atef Date : 2022-01-30
Best answers
51
Best answers
51
HII,
This must be a JSON typing error because the JS code is totally correct,
I noticed that you not using ‘ or " to store the JSON into the variable and that’s a mistake you should use it like
Jo Micheal Date : 2022-01-30
Yea that's it the JSON code you attached is working so good, sorry this is a beginners mistakes :)