How to parse response body
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-21-2024 06:16 AM
Response body from third party tool to ServiceNow:
{
"database": {
"allSheets": {
"facts": [
{
"cluster": {
"name": "Oracle",
"description": "This is used by db team.",
"Type": "database",
"Hosting": "Saas",
"life": {
"state": "Operational"
},
"rel1": {
"totalCount": 4,
"edges": [
{
"node": {
"Sheet": {
"name1": "problem",
"description": null
}
}
},
{
"node": {
"Sheet": {
"name1": "incident,
"description": null
}
}
},
{
"node": {
"Sheet": {
"name1": "Supply chain",
"description": null
}
}
},
{
"node": {
"Sheet": {
"name1": "inovation",
"description": null
}
}
}
]
},
"Owner": {
"totalCount": 2,
"edges": [
{
"node": {
"user": {
"userName": "abc@gmail.com"
},
"type": "OBSERVER",
"roles": [
{
"name": "Architect"
}
]
}
},
{
"node": {
"user": {
"userName": "xyz@gmail.com"
},
"otype": "RESPONSIBLE",
"roles": [
{
"name": "Developer"
}
]
}
}
]
}
}
},
{
"cluster": {
"name": "Adobe",
"description": "Adobe.",
"Type": "database",
"Hosting": "Saas",
"life": {
"state": "Operational"
},
"subscriptions": {
"totalCount": 0,
"edges": []
}
}
},
above response to be parsed and each record to be added in ServiceNow Custom table
Field | Value |
name | Oracle |
description | This is used by db team. |
Type | database |
Hosting | Saas |
life | Operational |
rel1 | problem |
incident | |
Owner | xyz@gmail.com |
otype | RESPONSIBLE |
work | Developer |

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-21-2024 06:30 AM
@s r1 You can JSON.parse to parse a JSON string and convert into an object in ServiceNow.
var someObj = JSON.parse(<your json string>);
var glideCustom = new GlideRecord('custom table name');
glideCustom.initalize();
glideCustom.name=someObj.facts[0].cluster.name;
glideCustom.description=someObj.facts[0].cluster.description;
glideCustom.type=someObj.facts[0].cluster.description;
//Similarly do it for other fields
glideCustom.insert();
Fore more information on JSON.parse please refer to https://www.servicenow.com/community/developer-blog/json-parsing/ba-p/2279166
Hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-21-2024 06:38 AM
The response is below. It should be parsed from database till name. name value is Oracle which will be added in custom table
{
"database": {
"allSheets": {
"facts": [
{
"cluster": {
"name": "Oracle",
"description": "This is used by db team.",

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-21-2024 07:11 AM
Please refer to the JSON.parse method and you will be able to parse data in your desired format, refer to the examples provided on this post https://www.servicenow.com/community/developer-blog/json-parsing/ba-p/2279166.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-21-2024 07:45 AM
Hello @s r1
Have simplified object (used some part) to get desired output.
You can try it in background script.
var r = {
"database": {
"allSheets": {
"facts": [{
"cluster": {
"name": "Oracle",
"description": "This is used by db team.",
"Type": "database",
"Hosting": "Saas",
"life": {
"state": "Operational"
},
"rel1": {
"totalCount": 4,
"edges": [{
"node": {
"Sheet": {
"name1": "problem",
"description": null
}
}
},
{
"node": {
"Sheet": {
"name1": "incident",
"description": null
}
}
}
]
}
}
}]
}
}
};
var clusterName = r.database.allSheets.facts[0].cluster.name;
var clusterDescription = r.database.allSheets.facts[0].cluster.description;
gs.print(clusterName);
gs.print(clusterDescription);
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates