Select Item from a JSON array that changes position

#1

I have a response with an array that has the components of the address listed as House Number, Street Name, City, State, Country, Zip etc. with each of them looking like this:

{
“long_name” : “United States”,
“short_name” : “US”,
“types” : [ “country”, “political” ]
},
{
“long_name” : “20817”,
“short_name” : “20817”,
“types” : [ “postal_code” ]
},

I just want the postal code, but it is not always in the same position in the array since some areas will also have other things listed above it such as locality, administrative area etc. How can I say I want the nth position of the array IF the “types” is postal_code?

This is from the Google API so I am hoping someone knows how I can do this!

(Karen Barker) #2

Hi @stellarun1

As long as the postal code is always the key for the array item then you’ll be able to refer to it as …types__0__postal_code. If this doesn’t work, please feel free to email us at support@flowxo.com including the full data output and we’ll happily take a closer look. :slight_smile:

#3

But I am wondering how to say:
"Go through this whole array until you find the result where types = “postal_code”. The problem is that I don’t know if it is the 5th, the 6th, the 7th or the 8th position in the array.

{{data__results__0__address_components__?__long_name}}. Can I use the Webhhook/Http module to do that? Or do I need some script somewhere?

(Karen Barker) #4

Hi @stellarun1

The position in the array shouldn’t matter as long as the key is always the same and the only key with this name in the array. If you can email us and include the full data output from the webhook then we will happily advise on the exact path that you’ll need to use. :slight_smile: