cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
johnjohn123
Super User
Super User

How I can go deep into a JSON data and loop thorugh an array

I have an external api which return the following JSON:-

{
  "resultSetMetaData": {
    "page": 0,
    "numPages": 2,
    "numRows": 3,
    "format": "json",
    "rowType": [
      {
        "name": "FIRST_NAME",
        "database": "PROD",
        "schema": "RIC",
        "table": "OWNER_VW",
        "type": "text",
        "scale": null,
        "precision": null,
        "nullable": true,
        "byteLength": 16777216,
        "collation": null,
        "length": 16777216
      },
      {
        "name": "LAST_NAME",
        "database": "PROD",
        "schema": "RIC",
        "table": "OWNER_VW",
        "type": "text",
        "scale": null,
        "precision": null,
        "nullable": true,
        "byteLength": 16777216,
        "collation": null,
        "length": 16777216
      },
      {
        "name": "EMAIL",
        "database": "PROD",
        "schema": "RIC",
        "table": "OWNER_VW",
        "type": "text",
        "scale": null,
        "precision": null,
        "nullable": true,
        "byteLength": 16777216,
        "collation": null,
        "length": 16777216
      },
      {
        "name": "CITY",
        "database": "PROD",
        "schema": "RIC",
        "table": "OWNER_VW",
        "type": "text",
        "scale": null,
        "precision": null,
        "nullable": true,
        "byteLength": 16777216,
        "collation": null,
        "length": 16777216
      },
      {
        "name": "ZIP",
        "database": "PROD",
        "schema": "RIC",
        "table": "OWNER_VW",
        "type": "text",
        "scale": null,
        "precision": null,
        "nullable": true,
        "byteLength": 16777216,
        "collation": null,
        "length": 16777216
      },
      {
        "name": "STATE",
        "database": "PROD",
        "schema": "RIC",
        "table": "OWNER_VW",
        "type": "text",
        "scale": null,
        "precision": null,
        "nullable": true,
        "byteLength": 16777216,
        "collation": null,
        "length": 16777216
      },
      {
        "name": "ADDRESS",
        "database": "PROD",
        "schema": "RIC",
        "table": "OWNER_VW",
        "type": "text",
        "scale": null,
        "precision": null,
        "nullable": true,
        "byteLength": 16777216,
        "collation": null,
        "length": 16777216
      },
      {
        "name": "PHONE",
        "database": "PROD",
        "schema": "RIC",
        "table": "OWNER_VW",
        "type": "text",
        "scale": null,
        "precision": null,
        "nullable": true,
        "byteLength": 16777216,
        "collation": null,
        "length": 16777216
      },
      {
        "name": "UID",
        "database": "PROD",
        "schema": "RIC",
        "table": "OWNER_VW",
        "type": "text",
        "scale": null,
        "precision": null,
        "nullable": true,
        "byteLength": 16777216,
        "collation": null,
        "length": 16777216
      }
    ]
  },
  "data": [
    [
      "0",
      "HoT",
      "Hot",
      "No_Email@no-email.com",
      "Miami",
      "33",
      "Florida",
      "",
      "",
      ""
    ],
    [
      "1",
      "Richie",
      "Hot",
      "No_Email@no-email.com",
      "Miami",
      "331",
      "Florida",
      "",
      "",
      ""
    ],
    [
      "2",
      "Jeff",
      "Hot",
      "No_Email@no-email.com",
      "Miami",
      "33",
      "Florida",
      "",
      "(0",
      "4"
    ]
  ],
  "code": "090001",
  "statementStatusUrl": "/api/statements/01a4d180-0b03-2ad4-0000-f67903a02826?requestId=4d32040e-ba17-4936-a013-7dd7ab1797aa",
  "requestId": "4d32040e-ba17-4936-a013-7dd7ab1797aa",
  "sqlState": "00000",
  "statementHandle": "01a4d180-0b03-2ad4-0000-f67903a02826",
  "message": "Statement executed successfully.",
  "createdOn": 1654725152956
}

 

now i want to loop through the items inside the data[] array, so how i can do so?

 

Now i wrote a test Flow and i create a Parse JSON action with the above JSON as the input and as the template, then i will get these.. so i only get rowType.. so how i can loop through the data[] array inside the rowType?

 

johnjohn123_0-1655159045919.png

 

Thanks

 

1 ACCEPTED SOLUTION

Accepted Solutions
eliotcole
Super User
Super User

Hi, @johnjohn123, if you simply want to loop through that data array either copy the following and paste it into the 'Select an output from previous steps' field:

@{outputs('Parse_JSON')?['data']}

Or tap the 'Expression' option next to 'Dynamic content' that you see in that pop-up when you are in that field, and paste in this:

outputs('Parse_JSON')?['data']

 

Once you're in the Apply to each you should be able to work with the column names within 'data' by using this expression in the expression builder:

items('Apply_to_each')[0]

That will bring the first piece of data from a given data listing, 1 will give the second, etc.

 

Alternatively, if you'd like to create a more meaningful dataset, make a Select action.  Then for each Key that you have named, select the appropriate value using the similar expression in the expression builder:

Key 1
item()[0]
Key 2
item()[1]
Key 3
item()[2]

... etc.

View solution in original post

1 REPLY 1
eliotcole
Super User
Super User

Hi, @johnjohn123, if you simply want to loop through that data array either copy the following and paste it into the 'Select an output from previous steps' field:

@{outputs('Parse_JSON')?['data']}

Or tap the 'Expression' option next to 'Dynamic content' that you see in that pop-up when you are in that field, and paste in this:

outputs('Parse_JSON')?['data']

 

Once you're in the Apply to each you should be able to work with the column names within 'data' by using this expression in the expression builder:

items('Apply_to_each')[0]

That will bring the first piece of data from a given data listing, 1 will give the second, etc.

 

Alternatively, if you'd like to create a more meaningful dataset, make a Select action.  Then for each Key that you have named, select the appropriate value using the similar expression in the expression builder:

Key 1
item()[0]
Key 2
item()[1]
Key 3
item()[2]

... etc.

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.

New Ideas Forum MPA.jpg

A new place to submit your Ideas for Power Automate

Announcing a new way to share your feedback with the Power Automate Team.

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.

MPA Licensing.jpg

Ask your licensing questions at the Power Automate AMA!

Join Priya Kodukula and the licensing team, super users and MVPs to find answers to your questions on Power Automate licensing.

Users online (4,840)