how to parse string into json object javascript -


this question has answer here:

i'm trying parse string json:

 "{'firstname':'jesper','surname':'aaberg','phone':'555-0100'}" 

i'm doing so:

var strjson = "{'firstname':'jesper','surname':'aaberg','phone':'555-0100'}"; console.log(json.parse(strjson)); 

but error message:

vm652:1 uncaught syntaxerror: unexpected token ' in json @ position 1 @ json.parse ()

does know missing , how can solve it?

you can replace single quotes double quotes , parse it.

var str =  "{'firstname':'jesper','surname':'aaberg','phone':'555-0100'}";    var o = json.parse(str.replace(/\'/g, "\""));  console.log(o)


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -