- 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-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-04-2022 05:32 PM
Thank you Richard... this works great...
