I am writing a function in node js which accepts 2 parameter - "param1" is "jsonObj" & "param2" is "xpath"(as String) but when I am trying to extract the value using jsonObj.xpath I am getting result as undefined as it is looking for xpath as a key in the json object rather than cDel.dInfo.env. Can someone please let me know how to extract the value of cDel.dInfo.env from jsonObj.
Below is the sample code -
const json = '{ "cDel": { "dInfo": { "env": "ACCEPTANCE", "ref": 103163 } } }';
const obj = JSON.parse(json);
var getValue = (jsonObj,xpath) => {
return jsonObj.xpath;
}
console.log(getValue(obj,"cDel.dInfo.env"));
Output is undefined. Expected Output is ACCEPTANCE.