cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
ericonline
Community Champion
Community Champion

Parse JSON Help

Hello, 

I'm trying to pull an array out of a JSON response and not having any luck. 
Can someone see what I'm missing?

Trigger: Button

Action1: HTTP Request

Action2: Parse JSON

  • I'm able to access all parameters just fine EXCEPT for the latitude and longitude "locked up" in the geometry/coordinates array:
  • {
      "type": "FeatureCollection",
      "metadata": {
        "generated": 1557358894000,
        "url": "https://earthquake.usgs.gov/fdsnws/event/1/query?format=geojson&starttime=2019-05-07T00%3a00%3a00.0000000&endtime=5%2f8%2f2019&latitude=39.0422528&longitude=-95.6719104&maxradiuskm=1000&orderby=magnitude-asc",
        "title": "USGS Earthquakes",
        "status": 200,
        "api": "1.8.1",
        "count": 1
      },
      "features": [
        {
          "type": "Feature",
          "properties": {
            "mag": 2.9,
            "place": "16km N of Snyder, Texas",
            "time": 1557260837307,
            "updated": 1557331308692,
            "tz": -360,
            "url": "https://earthquake.usgs.gov/earthquakes/eventpage/us70003i1i",
            "detail": "https://earthquake.usgs.gov/fdsnws/event/1/query?eventid=us70003i1i&format=geojson",
            "felt": 1,
            "cdi": 2.7,
            "mmi": null,
            "alert": null,
            "status": "reviewed",
            "tsunami": 0,
            "sig": 130,
            "net": "us",
            "code": "70003i1i",
            "ids": ",us70003i1i,",
            "sources": ",us,",
            "types": ",dyfi,geoserve,origin,phase-data,",
            "nst": null,
            "dmin": 0.028,
            "rms": 0.48,
            "gap": 36,
            "magType": "mb_lg",
            "type": "earthquake",
            "title": "M 2.9 - 16km N of Snyder, Texas"
          },
          "geometry": {
            "type": "Point",
            "coordinates": [
              -100.9142,
              32.8648,
              1.96
            ]
          },
          "id": "us70003i1i"
        }
      ]
    }
  • See how the latitude and longitude are not labeled in a "key" : "value" pair? 

I've tried a BUNCH of split() expressions and Select Actions to try and coerce them out. The best I can do is a Select Action where I get [ -100.9142, 32.8648, 1.96 ] as a single value. 

Ideally I want:

longitude: -100.9142
latitude: 32.8648
depth: 1.96

Ideas? 

Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
v-bacao-msft
Community Support
Community Support

Hi @ericonline ,

 

Since coordinates is an array, it seems that we can get the element value by index.

If the element values in coordinate of JSON response are in the order of [longitude, latitude, depth], please refer to the following method to get the element value.

First use Parse JSON action to separate the part containing the coordinates property, and then get the element value by the following expression.

longitude:

items('Apply_to_each')['geometry']['coordinates'][0]

latitude:

items('Apply_to_each')['geometry']['coordinates'][1]

depth:

items('Apply_to_each')['geometry']['coordinates'][2]

Image reference:

12.PNG

Hope it helps.

 

Best Regards,

Community Support Team _ Barry
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
v-bacao-msft
Community Support
Community Support

Hi @ericonline ,

 

Since coordinates is an array, it seems that we can get the element value by index.

If the element values in coordinate of JSON response are in the order of [longitude, latitude, depth], please refer to the following method to get the element value.

First use Parse JSON action to separate the part containing the coordinates property, and then get the element value by the following expression.

longitude:

items('Apply_to_each')['geometry']['coordinates'][0]

latitude:

items('Apply_to_each')['geometry']['coordinates'][1]

depth:

items('Apply_to_each')['geometry']['coordinates'][2]

Image reference:

12.PNG

Hope it helps.

 

Best Regards,

Community Support Team _ Barry
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

!~Wow @v-bacao-msft~!

 

Thank you. Your solution worked perfectly. Can you point me to documentation where I could learn about how to "..get the element value by index"? 

 

I see you're using [0], [1], [2] to access the index. I'd like to study this type of thing so I can learn more. 

 

Take care

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 (2,614)