- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā09-01-2022 07:51 AM
I have a flowdesigner action step to parse a complex nested JSON object; The data structure is as shown below; Can anyone help with the required parsing script needed to get the room data and data from the higher arrays ; ie I should have the floorID and BuildingID and roomID in 1 row of data to insert into the staging table
Attached is a cut of the json file; And below are the 3 fields I need to parse out for each room;
buildingID
floorID
roomID
Any help highly appreciated !
Solved! Go to Solution.
- Labels:
-
flow designer

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā09-02-2022 05:13 AM
Satish,
Something like this would do it in a background script, relatively trivial to put it into a script step in FD to put each string line into an output Array:-
// Declare the output array
var outputString = "";
// Declare the current Building ID variable
var currentBuildingId;
// Declare the current Floor ID variable
var currentFloorId;
// Declare the floors Array to improve loop performance.
var floorsArray = [];
// Declare the rooms Array to improve loop performance.
var roomsArray = [];
// Retrieve the data
var dataArray = JSON.parse(jsonString).data;
// For each building, retrieve the building ID and iterate the floors.
for(var i = 0; i< dataArray.length; i++){
currentBuildingId = dataArray[i].buildingID;
floorsArray = dataArray[i].floors;
// For each floor, retrieve the floor ID and iterate the rooms.
for(var j = 0; j < floorsArray.length; j++){
currentFloorId = floorsArray[j].floorID;
roomsArray = floorsArray[j].rooms;
for(var k = 0; k < roomsArray.length; k++){
outputString += currentBuildingId + "," + currentFloorId + "," + roomsArray[k].roomID + "\r\n";
}
}
}
gs.info(outputString);
Hope this helps,
Richard

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā09-01-2022 08:12 AM
Hi Satish,
I suggest you try something referring blog & let us know if you are stuck. It covers all possible scenarios.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā09-01-2022 08:23 AM
Hi,
please share the full JSON and attributes that you want to retrieve from payload?
Thanks,
Pavankumar
ServiceNow Community MVP 2024.
Thanks,
Pavankumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā09-01-2022 08:30 AM
Hi,
share the json string here.
Did you try JSON Parser step present in Flow Designer?
Regards
Ankur
Ankur
⨠Certified Technical Architect || ⨠9x ServiceNow MVP || ⨠ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā09-01-2022 08:35 AM