Is it possible to use conditions in a JSON array?

Hi all,

I’m working with the Places Autocomplete to get a place_id, but I then want to make a follow up call to the Google Places API with the place_id to get an accurate address format for my specific purpose (I need the long and short names for country, state and city).

I have the follow up API call working, as a result of the place_id I get from the Wappler Places Autocomplete.

I get an array of data back from Google’s API.

within this, ther are a varying amount of data points depending on the location, but what remains constant is the ‘type’.

So, for example, country ‘type’ is country, and state is ‘administrative_area_level_1’.

What i’m struggling with, is I want to only return for example the country short name.

In Wappler the schema just displays as

Screen Shot 2020-09-21 at 12.38.42 pm

And in the actual data returned:
Screen Shot 2020-09-21 at 12.39.16 pm

What would/should I write, say using a Set Value in Server connect to return only the ‘short_name’ of array data as that has a ‘types’ of “country” only?

Have you tried using a repeat step and selecting results as expression and apply the where formatter to it, the add the condition there you need there?
Then inside the repeat add the setvalue steps you need and bind the data from the repeat to them.

Thank you for the reply Teodor.

I haven’t but just taking a look now per your recommendation.

The issue I’m having when trying applying a where condition to the expression in the repeat step is that the full array is not available in the data picker:
Screen Shot 2020-09-21 at 12.57.02 pm

And the type is actually nested one level further down, you can see in the image above - I would somehow need to get a where condition on: data.results.[0].address_components and only return the array that has ‘types’ “country” nested within it.

But I only have the results array available to pick in the data picker.

Do you think this would work? I’m not sure the right way to run the where on the final nesting on the array within address_components:

Screen Shot 2020-09-21 at 12.59.39 pm

@George will check this issue.

1 Like