cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
grantculp
Frequent Visitor

Parse JSON - Google API Geocoding

Hey semi-new to flows and having trouble parsing this JSON and getting the data I need out of it.

 

I need the postal code, where the types are locality and political, administrative_area_level_1, country.

 

I think I need to do this within a loop - set the variables before and then assign the values to those variables if the type match what I am looking for.

 

Coming from a different background than Power Automate so just want to see if there is a way to do this.

 

Here is the JSON: 

{
"results" : [
{
"address_components" : [
{
"long_name" : "60048",
"short_name" : "60048",
"types" : [ "postal_code" ]
},
{
"long_name" : "Libertyville",
"short_name" : "Libertyville",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Lake County",
"short_name" : "Lake County",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "Illinois",
"short_name" : "IL",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "United States",
"short_name" : "US",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "Libertyville, IL 60048, USA",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 42.363889,
"lng" : -87.89177289999999
},
"southwest" : {
"lat" : 42.21986589999999,
"lng" : -88.01905699999999
}
},
"location" : {
"lat" : 42.2868698,
"lng" : -87.94328370000001
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 42.363889,
"lng" : -87.89177289999999
},
"southwest" : {
"lat" : 42.21986589999999,
"lng" : -88.01905699999999
}
}
},
"place_id" : "ChIJh9RiGzORD4gRZ4tlvYyj5gA",
"types" : [ "postal_code" ]
}
],
"status" : "OK"
}

1 ACCEPTED SOLUTION

Accepted Solutions
mahoneypat
Solution Sage
Solution Sage

Here is one way extract the postal code.  I put your JSON in a string variable, then used Parse_Json (using the same JSON as the sample to generate the schema), and finally this expression in a compose step (as an example, but you can use same expression elsewhere) to get the "long_name" which is the postal code.

 

body('Parse_JSON')?['results'][0]?['address_components'][0]['long_name']

 

The [0]'s are just getting the first element in those respective arrays.

mahoneypat_0-1616206113027.png

 

mahoneypat_1-1616206250890.png

 

Pat

 

 

View solution in original post

1 REPLY 1
mahoneypat
Solution Sage
Solution Sage

Here is one way extract the postal code.  I put your JSON in a string variable, then used Parse_Json (using the same JSON as the sample to generate the schema), and finally this expression in a compose step (as an example, but you can use same expression elsewhere) to get the "long_name" which is the postal code.

 

body('Parse_JSON')?['results'][0]?['address_components'][0]['long_name']

 

The [0]'s are just getting the first element in those respective arrays.

mahoneypat_0-1616206113027.png

 

mahoneypat_1-1616206250890.png

 

Pat

 

 

View solution in original post

Helpful resources

Announcements
Process Advisor

Introducing Process Advisor

Check out the new Process Advisor community forum board!

MPA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Users online (41,068)