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

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
Highlighted
Dual Super User III
Dual Super User III

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
Highlighted
Dual Super User III
Dual Super User III

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.
Highlighted

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.

Highlighted
Dual Super User III
Dual Super User III

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

Highlighted

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
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

Power Platform ISV Studio

Power Platform ISV Studio

ISV Studio is designed to become the go-to Power Platform destination for ISV’s to monitor & manage published applications.

Top Solution Authors
Top Kudoed Authors
Users online (15,815)