- 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
Thanks & Best regards,
Medi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2025 04:49 PM
Thank you Medi..!
so total two methods
gs.info(obj1.data.hasOwnProperty("info2"))
gs.info(!!obj1.data.info2);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2025 04:53 PM
You are welcome @Supriya25!
As I believe I have answered all your queries, could you please mark the answers which helped you as helpful and accept the solutions so that it benefit future readers.
Thanks & Best regards,
Medi
