- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2025 11:35 AM
Hi All,
Kindly help me how to identify "info" either it is starting with " { " or "[ { "
example 1:
{
data: {
info: {
"name": "servicenow"
}
}
}
example 2:
{
data: {
info: [
{
"name":"Servicenow"
},{
"name":"SNOW"
}
]
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2025 02:42 PM
Hi @Supriya25
You can use:
var obj1 = {
data: {
info: {
"name": "servicenow"
}
}
};
//Multiple Info objects
var obj2 = {
data: {
info: [{
"name": "Servicenow"
}, {
"name": "SNOW"
}]
}
}
//Check if given input is an array
Array.isArray(YOUR_ARRAY);
//Function to check if a given input is JSON
function isJsonObject(value) {
return typeof value === "object" && value !== null && !Array.isArray(value);
}
gs.info(Array.isArray(obj1.data.info)); //false
gs.info(Array.isArray(obj2.data.info)); //true
gs.info(isJsonObject(obj1.data.info)); //true
gs.info(isJsonObject(obj2.data.info)); //false
If you found this helpful, please hit the thumbs-up button and mark as correct. That helps others find their solutions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2025 02:42 PM
Hi @Supriya25
You can use:
var obj1 = {
data: {
info: {
"name": "servicenow"
}
}
};
//Multiple Info objects
var obj2 = {
data: {
info: [{
"name": "Servicenow"
}, {
"name": "SNOW"
}]
}
}
//Check if given input is an array
Array.isArray(YOUR_ARRAY);
//Function to check if a given input is JSON
function isJsonObject(value) {
return typeof value === "object" && value !== null && !Array.isArray(value);
}
gs.info(Array.isArray(obj1.data.info)); //false
gs.info(Array.isArray(obj2.data.info)); //true
gs.info(isJsonObject(obj1.data.info)); //true
gs.info(isJsonObject(obj2.data.info)); //false
If you found this helpful, please hit the thumbs-up button and mark as correct. That helps others find their solutions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2025 03:59 PM - edited 03-12-2025 04:01 PM
Thanks
one last Question , imagine "data" is very huge JSON out of that huge JSON how to get to know "data" object has "info2" or not.
var obj1 = {
data: {
info: {
"name": "servicenow"
},
info1:{
"name":"QL"
},
"info2: {
"name":"TU"
}
}
};
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2025 04:08 PM
Hi @Supriya25
You can do that as follow (notice there are !! not !):
var obj1 = {
data: {
info: {
"name": "servicenow"
},
info1: {
"name": "QL"
},
info2: {
"name": "TU"
}
}
};
var obj2 = {
data: {
info: {
"name": "servicenow"
},
info1: {
"name": "QL"
},
}
};
gs.info(!!obj1.data.info2); // true
gs.info(!!obj2.data.info2); //false
If you found this helpful, please hit the thumbs-up button and mark as correct. That helps others find their solutions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2025 04:27 PM
gs.info(!!obj1.data.info2); // true gs.info(!!obj2.data.info2); //false
Apart of this method any other way to to identify ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2025 04:36 PM
There other ways. You can use this one also:
object.hasOwnProperty(KEY)
Example:
var obj1 = {
data: {
info: {
"name": "servicenow"
},
info1: {
"name": "QL"
},
info2: {
"name": "TU"
}
}
};
var obj2 = {
data: {
info: {
"name": "servicenow"
},
info1: {
"name": "QL"
},
}
};
gs.info(obj1.data.hasOwnProperty("info2")); // true
gs.info(obj2.data.hasOwnProperty("info2")); //false
If you found this helpful, please hit the thumbs-up button and mark as correct. That helps others find their solutions.