JSON API - How to Limit Dataset to City/State or Lat/Lon

Hi,

While AppGyver engineering looks into possible issues with my data resource on Android devices, in this thread, and because this data resource works well on iPhone, I have a question about displaying a set of data from a specific region.

So I have this example JSON file: https://www.webmagi.com/wmclients/shine/ntaa/RATest.json. Within it are air quality data sets for two cities (Aberdeen WA, and Phoenix AZ). Looking at this JSON file in a browser, you can see the available schema, but I only need a few of these (Issue Date, Reporting Area, Pollutant, Aqi Value, Aqi Category, and Discussion).

I can pull data into AppGyver components individually, one at a time, using this schema, but this is only good for testing. In the real world, a user will want to type in a city/state combo, or if GPS Location logic can somehow be used to match the Latitude and Longitude of the data set, and then a complete dataset for that region would be displayed on the page.

:mag_right: Is there a way, looking at the above sample JSON file, to sort a dataset by city/state, or Latitude and Longitude, and then have just that dataset displayed on the page?

Thank you!

Hey!

Yes it is possible! There’s a couple of ways, I’m assuming you are using that json as a data resource and accessing it through a data variable? In that case you have a couple of options:

Depending on that API, you might be able to add querys to your GET request, for example getting the data based on a specific state. Do you know if that’s possible?

Another option that should work in either case, is to use formulas for the data variable. Opening the data variable tab, selecting the data variable, and opening the logic canvas you should see this:

In the Set Data Variable node, you can use a formula to filter all the records to include just specific ones, and only those records get saved in the data variable. Just change the node’s “Record collection” (screenshot) property to a formula, and add something like this:

SELECT(outputs["Get record collection"].records, LOOKUP(item, "State Code") == "theCodeYouWant")

Then you can use the data variable to display the correct data set on your page. If you want to change the schema of the data variable to include just the specific properties, you can wrap that SELECT(...) function with a MAP, more info about MAP here.

Let me know if I misunderstood the situation or if I can help you further!

1 Like

Hi Cecilia,

Thank you so much for taking the time to go through this. Due to the data format currently provided by the EPA’s AirNow service (no JSON and no CORS enabled API), I decided to use a temp solution to get the app launched. But I still plan to implement this functionality, and your ideas will be instrumental in helping me get there.

I will dive into this in the coming weeks, and get back to you if I have any questions.

Thanks again!

1 Like