Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2021 06:36 AM
Hi,
here is sample script on how to remove json object from array of json objects
var json = '[{"name":"Abel","email":"abel@example.com"},{"name":"Beth","email":"beth@example.com"}]';
var toRemove = 'Abel';
var finalArr = [];
var parser = JSON.parse(json);
for(var i=0;i<parser.length;i++){
var obj = parser[i];
var newParser = JSON.parse(JSON.stringify(obj));
if(newParser.name != toRemove){
finalArr.push(obj);
}
}
gs.info(JSON.stringify(finalArr));
Output:
[0:00:00.063] Script completed in scope global: script
Script execution history and recovery available here
*** Script: [{"name":"Beth","email":"beth@example.com"}]
Regards
Ankur
Regards,
Ankur
✨ Certified Technical Architect || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader
Ankur
✨ Certified Technical Architect || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader