How to dynamically extract an object fields

  • The goal is to extract the value of the “UnitTypeId” key from each entry within an object named “Unit.”

Description:

  • The “Unit” object contains multiple entries, each identified by a unique number (e.g., “5028830” and “5028956”).
  • Each entry has a sub-object called “@attributes,” which, in turn, contains various properties, one of which is “UnitTypeId.”
  • The task is to dynamically iterate through all entries within “Unit” and extract the value associated with the “UnitTypeId” key in each entry.

You guys have any idea how I can achieve this?


 "Unit": {
                          "5028830": {
                              "@attributes": {
                                  "UnitNumber": "109-B",
                                  "FloorPlanName": "QUARTO INDIVIDUAL PLUS (APTO 4 QUARTOS)",
                                  "Availability": "Available",
                                  "Status": "Vacant Ready (Available)",
                                  "AvailableOn": "01/01/2020",
                                  "FloorplanId": 1152636,
                                  "UnitTypeId": 653872,
                                  "PropertyUnitId": 5028830,
                                  "PropertyId": 1311265,
                                  "FloorId": 2676147,
                                  "FloorNumber": "1",
                                  "BuildingId": 88719,
                                  "BuildingName": "A",
                                  "OccupancyType": "Student",
                                  "IsAffordable": "0",
                                  "HasPricing": "1",
                                  "WebVisible": "1"
                              }
                          },
                          "5028956": {
                              "@attributes": {
                                  "UnitNumber": "409-B",
                                  "FloorPlanName": "QUARTO INDIVIDUAL PLUS (APTO 4 QUARTOS)",
                                  "Availability": "Available",
                                  "Status": "Vacant Ready (Available)",
                                  "AvailableOn": "01/01/2020",
                                  "FloorplanId": 1152636,
                                  "UnitTypeId": 653872,
                                  "PropertyUnitId": 5028956,
                                  "PropertyId": 1311265,
                                  "FloorId": 2676153,
                                  "FloorNumber": "4",
                                  "BuildingId": 88719,
                                  "BuildingName": "A",
                                  "OccupancyType": "Student",
                                  "IsAffordable": "0",
                                  "HasPricing": "1",
                                  "WebVisible": "1"
                              }
                          }
                      }
1 Like

Hello Aram,

you can achieve the results your looking for using an IML function. I converted the data you sent into a json object.

Then I used an IML function to generate an array of the "UnityTypeId"s

{{map(map(map(toArray(20.Unit); “value”); “@attributes”); “UnitTypeId”)}}

You can use this same strategy to generate corresponding arrays for any other filed within the @attributes object by changing “UnitTypeId” to the desired field.

5 Likes

Hi Brett!

Thanks a lot for the answer, it worked wonders, here’s a screenshot of it:

You saved us a lot of trouble!

2 Likes