How to Parse JSON from Web Request
Hello,
I am new to both Workflow 5 and APIs. I am trying to create a workflow that will collect weather data from an API so that I can grab the aspects of the weather observations I need and add them to a new record in a SQL table. I'm sure I can figure out the bulk of the workflow on my own, but I don't know how to go about grabbing the pieces of information I need from the JSON returned from the API.
I looked at the "Earthquake API Request" sample workflow, but it doesn't do what I want. I don't need the geometry or symbol from the resulting JSON. I just want the description, temperature, windSpeed, and windDescShort values.
Here is a URL that gives you an idea of what the resulting JSON looks like:
https://developer.here.com/documentation/examples/rest/auto_weather/weather-observation-lat-long
I was playing around with the Parse JSON activity to try to spit one of the values out in an alert, but I haven't had any luck yet.
Any help would be much appreciated!
Thanks,
Denise
-
You don't need to do any parsing. Just use a Send Web Request with these parameters:
={ product: "observation", latitude: 52.516, longitude: 13.389, oneobservation: true, app_id: "devportal-demo-20180625", app_code: "9v2BkviRwi9Ot26kp2IysQ" }- Expect: json
This will give you an object with everything from the json. E.g. an Alert with
=$webRequest1.json.observations.location[0].observation[0].description
will show 'Partly sunny. Quite cool.'
0 -
This is exactly what I needed! The only experience I've had with JSON has been making small edits to the config files of the HTML viewer, so I honestly had no idea what I was doing in this case.
The syntax you gave for showing the description in an alert is extremely helpful! Thank you so much, Berend!
0
Bitte melden Sie sich an, um einen Kommentar zu hinterlassen.
Kommentare
2 Kommentare