Received a JSON response similar to the one below
{
"SNGS": {
"$": {
"xmlns": "csng",
"xmlns:ns2": "http://www.w3.org/1999/xlink"
},
"Defect": [{
"$": {
"id": "DCV19294",
"ns2:href": "https://mywebsite.com/api/beta//bug/DCSV19294"
},
"Field": [{
"_": "4",
"$": {
"name": "Severity"
}
}, {
"_": "N",
"$": {
"name": "Status"
}
}]
}]
}
}
Attempting to extract values from the following keys:
- id
- status
Trying to parse the JSON and retrieve values by key using the code snippet below, but receiving 'undefined' in the alert. Why is that?
const data='{"SNGS":{"$":{"xmlns":"csng","xmlns:ns2":"http://www.w3.org/1999/xlink"},"Defect":[{"$": {"id":"DCV19294","ns2:href":"https://mywebsite.com/api/beta//bug/DCSV19294"},"Field":[{"_":"4","$":{"name":"Severity"}},{"_":"N","$":{"name":"Status"}}]}]}}'
const parsedData = JSON.parse(data);
console.log(parsedData.id);
console.log(parsedData.Status);
Desiring to extract id (DCV19294) and status (N) from the provided JSON. Assistance would be appreciated.