Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

unexpected token r in JSON at position 1 While trying to parse simple JSON

I’m trying to parse this simple JSON,
but its giving me an error:

let myjson = "{rahul: 'kumar', parul: 'sinha'}"
let result = JSON.parse(myjson)
console.log(result)

but it is giving me this error:

Uncaught SyntaxError: Unexpected token r in JSON at position 1
    at JSON.parse

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

JSON doesn’t understand Single quotes (‘)

so use double quotes instead.

let myjson = '{"rahul": "kumar", "parul": "sinha"}'
let result = JSON.parse(myjson)
console.log(result)

Learn more Here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading