I have a string(var) that I parse as JSON in javascript. But as soon as I do that I get an error stating
Uncaught SyntaxError: Unexpected token c in JSON at position 13
var DL_response = {"result":"{"cov_details":[{"issue_date":"UNIT
OFFICE,NEYVELI","cov":"MCWG"}],"dl_number":"TN39Y20100000784","address":"PERIYA COLONY KO PAVAZHANGUDI
VIRUDHACHALAM TK","issue_date":"24-03-2020","dob":"21-03-1971","name":"VICNESWARAN
S","blood_group":"","validity":{"transport":"","non-transport":"24-03-2010 to 23-03-
2030"},"father_husband":"SELVARAJ"}","status-code":"101","request_id":"a9642ae9-2f10-4e9a-9f7e-
c3ee1a9a2dbe"}
var Driving_License = JSON.parse(DL_response);
What might be causing this error? Is it because of any special characters?
First of all, your JSON is invalid. And second of all, it's not a JSON string but a JavaScript Object itself. There is no need to parse it again. If the object was valid, you could access it directly without further parsing.
Here is the data I've fixed.
var DL_response = {
"result":{
"cov_details":[
{
"issue_date":"UNIT OFFICE,NEYVELI",
"cov":"MCWG"
}
],
"dl_number":"TN39Y20100000784",
"address":"PERIYA COLONY KO PAVAZHANGUDI VIRUDHACHALAM TK",
"issue_date":"24-03-2020",
"dob":"21-03-1971",
"name":"VICNESWARANS",
"blood_group":"",
"validity":{
"transport":"",
"non-transport":"24-03-2010 to 23-03-2030"
},
"father_husband":"SELVARAJ",
"status-code":"101",
"request_id":"a9642ae9-2f10-4e9a-9f7e-c3ee1a9a2dbe"
}
}
console.log(DL_response.result.dob)
// output: 21-03-1971
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments