USING IBP BPM 8.6:
I have a Json object as follows:
tw.local.stringifiedJSON = "{"name":"ahmed","age":"20","job":{"salary":"1000","position":"developer"}}";
I parsed into a javascript object:
var parsedJSONTW= JSON.parse(tw.local.stringifiedJSON);
I want to check if each key is complex (nested or has other keys and values in it like "job") or flat (has a value only like "name")
var finObj={};
var i;
for ( i in parsedJSONTW) {
if (finObj[i] === undefined) { finObj[i] = {}; }
tw.local.propertiesOfObject=Object.getOwnPropertyNames(parsedJSONTW[i]);
if(tw.local.propertiesOfObject==null || tw.local.propertiesOfObject.listLength==0)
{
finObj[i]= parsedJSONTW[i]; //expected to have name and age fields only
}
Using object.getOwnProperty() doesn't work with a flat object and gives the error of "expected an object but found a string"
You can use "typeof" for this: