Querying and transforming object (using Google Places API)

Options

Hi, I am using the Google Places API and would like to extract some information and write it to a table.

I would like to save the address in a table of "service providers". The concept of what is a city differs hugely when looking at a global level. So I would like to store the administrative_area_levels, als Google calls them.

I thought of storing them as an object.

The response contains this:

[
{
"long_name": "Jalan Munduk Tengah",
"short_name": "Jl. Munduk Tengah",
"types": ["route"]
},
{
"long_name": "Kabupaten Badung",
"short_name": "Kabupaten Badung",
"types": ["administrative_area_level_2", "political"]
},
{
"long_name": "Bali",
"short_name": "Bali",
"types": ["administrative_area_level_1", "political"]
},
{
"long_name": "80351",
"short_name": "80351",
"types": ["postal_code"]
}]

I would like to transform and save it like this:

{
"administrative_area_level_1": "Bali",
"administrative_area_level_2": "Kabupaten Badung",
"administrative_area_level_3": "Kecamatan Mengwi"
}

Unfortunately I tried many filters and functions but couldn't get it done-

Tagged:

Comments

  • Louis Machado - CSA
    Louis Machado - CSA Administrator

    ADMIN

    Options

    Hello Marfi,

    If you recreate the function stack below, you should be good to go.

  • marfi
    marfi Member
    edited October 2023
    Options

    Hi @Louis Machado - CSA

    Thank you very much. That worked well.

    Now I tried to only merge the item_transformed to the transformed_array, when it contains "administrative_area_level", but cannot get it to work.

    I used set_conditional like seen on the screenshot below, but the variable remains empty then. Any idea?

  • Louis Machado - CSA
    Louis Machado - CSA Administrator

    ADMIN

    edited October 2023
    Options

    Hello Marfi,

    I fixed your function stack by adding one function before the loop called Array: Find All Elements, setting it up as shown in the image, and I called it only_with_administrative. After that replace the Google_places array with this on only_with_administrative.

    The whole process as well as the test to show it works can be seen below.

  • marfi
    marfi Member
    Options

    Thank you so much, I made it work with that function.