cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
JmeBrey
Helper I
Helper I

How to drill into JSON

Hi Everyone

 

I am using a HTTP request and after using parse JSON to get the following.

 

 

{
  "body": {
    "Members": {
      "Member": [
        {
          "@Member_Id": "172",
          "DisplayAs": "user 1",
          "Gender": "F",
          "CurrentStatus": {
            "StartDate": "2019-12-12T00:00:00"
          },
          "Addresses": {
            "Address": [
              {
                "@Type_Id": "6",
                "Address1": "http://www.google.com"
              },
              {
                "@Type_Id": "1",
                "Email": "user1@gmail.uk",
                "OtherAddress": null
              }
            ]
          }
        },
        {
          "@Member_Id": "172",
          "DisplayAs": "user 2",
          "Gender": "M",
          "CurrentStatus": {
            "StartDate": "2019-05-12T00:00:00"
          },
          "Addresses": {
            "Address": [
              {
                "@Type_Id": "6",
                "Address1": "http://www.bing.com"
              },
              {
                "@Type_Id": "1",
                "Email": "user2@hotmail.com",
                "OtherAddress": null
              }
            ]
          }
        }
      ]
    }
  }
}

 

 
I am trying to get the email addresses but in all my attempts I get the same error...

 

json1.pngjson2.png


How would I drill into the response and get the email addresses for both users?

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions

You should select 'Member', not addresses.  You use an index to get the specific address you want from the addresses array.  see the screenshot below.

image.png



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

View solution in original post

4 REPLIES 4
Pstork1
Dual Super User
Dual Super User

After you parse the JSON add the Address dynamic content to an Apply to Each loop to loop through the addresses.  The email is in the second entry of the address array in your sample.  Assuming it always is you can get the email from the array inside the loop using the following.

items('Apply_to_each')?['Addresses']?['Address'][1]?['Email']


-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

Thanks for the response.

 

Unfortunately If I add a apply to each loop under the Parse JSON and select 'Address' the Flow automatically places that as a nested loop in another apply to each loop of 'Member' (apply to each 2 is the auto generated loop added by Flow)

 

json3.png

 

ExpressionEvaluationFailed. The execution of template action 'Apply_to_each_2' failed: the result of the evaluation of 'foreach' expression '@body('Parse_JSON')?['body']?['Members']?['Member']' is of type 'Null'. The result must be a valid array.

 

 

I get the same error saying that something is null. I can clearly see the data from the HTTP request and the JSON after it is parsed so I don't understand why it would be saying something is null.

You should select 'Member', not addresses.  You use an index to get the specific address you want from the addresses array.  see the screenshot below.

image.png



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

Thank you so much for your help, I really appreciate it as I was so stuck. It worked and I can continue building the flow.

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.

Carousel_PP_768x460_Wave2 (1).png

2022 Release Wave 2 Plan

Power Platform release plan for the 2022 release wave 2 describes all new features releasing from October 2022 through March 2023.

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.

365 EduCon 768x460.png

Microsoft 365 EduCon

Join us for two optional days of workshops and a 3-day conference, you can choose from over 130 sessions in multiple tracks and 25 workshops.

Users online (3,098)