cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Marcin83
Frequent Visitor

How to convert json object (from API body) into array (nested objects)

Hello,

 

last couple of days I'm struggling with this problem. After parsing json response from Api I have an object like below. I would like to convert it to a table of object which later I could iterate and access to each item properties.

 

{
"2708526": {
"paymentsname": "nazwaplaytnosci",
"zweryfikowano_wplataid": "NIE",
"nadawca_wplaty": "",
"rodzaj_wplaty_wplaty": "",
"konto_nazwa_wplataid": "",
"data_transakcji_wplatyid": "",
"data_ksiegowania_wplatyid": "",
"paymentstitle": "test1",
"kwota_wplaty_id": "100,00 zł",
"paymentsvalue": "100,00 zł"
},
"2708527": {
"paymentsname": "nazwaplaytnosci",
"zweryfikowano_wplataid": "NIE",
"nadawca_wplaty": "",
"rodzaj_wplaty_wplaty": "",
"konto_nazwa_wplataid": "",
"data_transakcji_wplatyid": "",
"data_ksiegowania_wplatyid": "",
"paymentstitle": "tytulplatnosci",
"kwota_wplaty_id": "200,00 zł",
"paymentsvalue": "200,00 zł"
},
"2708528": {
"paymentsname": "nazwaplatnosci3",
"zweryfikowano_wplataid": "NIE",
"nadawca_wplaty": "",
"rodzaj_wplaty_wplaty": "",
"konto_nazwa_wplataid": "",
"data_transakcji_wplatyid": "",
"data_ksiegowania_wplatyid": "",
"paymentstitle": "tytulplatnosci3",
"kwota_wplaty_id": "300,00 zł",
"paymentsvalue": "300,00 zł"
}
}
 
The final array items should be this ones: 2708526, 2708527, 2708528.
Numbers/items are not know and random numbers can have depending from API request used.
 
Please help because I lost a week on it already.
 
 
2 REPLIES 2
Aakash_raj
Regular Visitor

Hi @Marcin83,

 

You can easily do this thing. First, you have to initialize the array object. You have to iterate the main object after that inside you have to iterate other properties and use append to array action to add all the details in one array. after that you can easily access each item's properties.

if you get an issue with the flow share your flow or API details. I'll help to fix this.

 

Thanks

Marcin83
Frequent Visitor

Below is API response from which I want to extract as an array items, for this case: 2708526, 2708527, 2708528.

The problem in my opinion is that items are not located between [ ] which would allow us probably straight away iterate because built-in parser would see it as a table. Now it sees only as a very nested objects within objects.

If you have any idea how to iterate please give me an example.

 

 

{
  "status": 1,
  "result": {
    "headers": {
      "paymentsname": "Nazwa płatności",
      "zweryfikowano_wplataid": "Zweryfikowano",
      "nadawca_wplaty": "Nadawca",
      "rodzaj_wplaty_wplaty": "Rodzaj wpłaty",
      "konto_lextio_nazwa_wplataid": "Konto Lextio - nazwa",
      "data_transakcji_wplatyid": "Data transakcji",
      "data_ksiegowania_wplatyid": "Data księgowania",
      "paymentstitle": "Tytuł płatności",
      "kwota_wplaty_id": "Kwota Wpłaty",
      "paymentsvalue": "Wartość"
    },
    "records": {
      "2708526": {
        "paymentsname": "nazwaplaytnosci",
        "zweryfikowano_wplataid": "NIE",
        "nadawca_wplaty": "",
        "rodzaj_wplaty_wplaty": "",
        "konto_lextio_nazwa_wplataid": "",
        "data_transakcji_wplatyid": "",
        "data_ksiegowania_wplatyid": "",
        "paymentstitle": "test1",
        "kwota_wplaty_id": "100,00 zł",
        "paymentsvalue": "100,00 zł"
      },
      "2708527": {
        "paymentsname": "nazwaplaytnosci",
        "zweryfikowano_wplataid": "NIE",
        "nadawca_wplaty": "",
        "rodzaj_wplaty_wplaty": "",
        "konto_lextio_nazwa_wplataid": "",
        "data_transakcji_wplatyid": "",
        "data_ksiegowania_wplatyid": "",
        "paymentstitle": "tytulplatnosci",
        "kwota_wplaty_id": "200,00 zł",
        "paymentsvalue": "200,00 zł"
      },
      "2708528": {
        "paymentsname": "nazwaplatnosci3",
        "zweryfikowano_wplataid": "NIE",
        "nadawca_wplaty": "",
        "rodzaj_wplaty_wplaty": "",
        "konto_lextio_nazwa_wplataid": "",
        "data_transakcji_wplatyid": "",
        "data_ksiegowania_wplatyid": "",
        "paymentstitle": "tytulplatnosci3",
        "kwota_wplaty_id": "300,00 zł",
        "paymentsvalue": "300,00 zł"
      }
    },
    "permissions": {
      "2708526": {
        "isEditable": true,
        "moveToTrash": true
      },
      "2708527": {
        "isEditable": true,
        "moveToTrash": true
      },
      "2708528": {
        "isEditable": true,
        "moveToTrash": true
      }
    },
    "rawData": {
      "2708526": {
        "paymentsname": "nazwaplaytnosci",
        "zweryfikowano_wplataid": "NIE",
        "nadawca_wplaty": "",
        "rodzaj_wplaty_wplaty": "",
        "konto_lextio_nazwa_wplataid": "",
        "data_transakcji_wplatyid": null,
        "data_ksiegowania_wplatyid": null,
        "paymentstitle": "test1",
        "kwota_wplaty_id": "100.00000000",
        "paymentsvalue": "100.00000000"
      },
      "2708527": {
        "paymentsname": "nazwaplaytnosci",
        "zweryfikowano_wplataid": "NIE",
        "nadawca_wplaty": "",
        "rodzaj_wplaty_wplaty": "",
        "konto_lextio_nazwa_wplataid": "",
        "data_transakcji_wplatyid": null,
        "data_ksiegowania_wplatyid": null,
        "paymentstitle": "tytulplatnosci",
        "kwota_wplaty_id": "200.00000000",
        "paymentsvalue": "200.00000000"
      },
      "2708528": {
        "paymentsname": "nazwaplatnosci3",
        "zweryfikowano_wplataid": "NIE",
        "nadawca_wplaty": "",
        "rodzaj_wplaty_wplaty": "",
        "konto_lextio_nazwa_wplataid": "",
        "data_transakcji_wplatyid": null,
        "data_ksiegowania_wplatyid": null,
        "paymentstitle": "tytulplatnosci3",
        "kwota_wplaty_id": "300.00000000",
        "paymentsvalue": "300.00000000"
      }
    },
    "numberOfRecords": 3,
    "isMorePages": false
  }
}

 

Parsing with built-in action doesn't help. On output its exactly the same as input. So next I decided to extract from json object that is interest form me by initiating variable (raw data below of this step)

{
    "variables": [
        {
            "name": "ApiResultRecords",
            "type": "Object",
            "value": {
                "2708526": {
                    "paymentsname": "nazwaplaytnosci",
                    "zweryfikowano_wplataid": "NIE",
                    "nadawca_wplaty": "",
                    "rodzaj_wplaty_wplaty": "",
                    "konto_lextio_nazwa_wplataid": "",
                    "data_transakcji_wplatyid": "",
                    "data_ksiegowania_wplatyid": "",
                    "paymentstitle": "test1",
                    "kwota_wplaty_id": "100,00 zł",
                    "paymentsvalue": "100,00 zł"
                },
                "2708527": {
                    "paymentsname": "nazwaplaytnosci",
                    "zweryfikowano_wplataid": "NIE",
                    "nadawca_wplaty": "",
                    "rodzaj_wplaty_wplaty": "",
                    "konto_lextio_nazwa_wplataid": "",
                    "data_transakcji_wplatyid": "",
                    "data_ksiegowania_wplatyid": "",
                    "paymentstitle": "tytulplatnosci",
                    "kwota_wplaty_id": "200,00 zł",
                    "paymentsvalue": "200,00 zł"
                },
                "2708528": {
                    "paymentsname": "nazwaplatnosci3",
                    "zweryfikowano_wplataid": "NIE",
                    "nadawca_wplaty": "",
                    "rodzaj_wplaty_wplaty": "",
                    "konto_lextio_nazwa_wplataid": "",
                    "data_transakcji_wplatyid": "",
                    "data_ksiegowania_wplatyid": "",
                    "paymentstitle": "tytulplatnosci3",
                    "kwota_wplaty_id": "300,00 zł",
                    "paymentsvalue": "300,00 zł"
                }
            }
        }
    ]
}

 

After this step I tried 50 different approaches and cannot move forward to get three items from value(object) as an array.

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

May UG Leader Call Carousel 768x460.png

June User Group Leader Call

Join us on June 28 for our monthly User Group leader call!

MPA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

Power Automate Designer Feedback_carousel.jpg

Help make Flow Design easier

Are you new to designing flows? What is your biggest struggle with Power Automate Designer? Help us make it more user friendly!

Users online (3,197)