cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
AndrewC
Microsoft
Microsoft

How to parse json in a condition?

I'm tyrying to parse some json returned from a HTTP request. 

The request works fine, but I'm having trouble getting the variable I want test extracted correctly. 

The json returned is:

 

{ "Time":"12 Jul 2016 930 AM EST " ,"Direction":"225" ,"Gusts":"2.4" ,"Wind":"1.7" ,"Tempature":"78.9" ,"KPTime":"2016-07-12 14:24" ,"KPCard":"SSW" ,"KPDirection":"202" ,"KPGusts":"7.00" ,"KPWind":"6.61" }

 

I want to parse out out the value after this "Gusts":"2.4" to be value 2.4 and run a condition on it:

I assumed I could take the body as  'Gusts' : 'ERGust' and a condition of:

 

@greater(body('Http')['ERGust'], 5)

 

snip_20160712105444.png

 

 

 

 

The Flow is at:https://flow.microsoft.com/manage/flows/0f4174dc-4ffe-4e51-90af-f0ecbcf25981

 

Any thoughts?

 

Thanks

Andrew

 

5 REPLIES 5
olebeerenberg
New Member

Did you find a way to get this to work? Same situation

The above example is very close but not quite correct. If you have 

{ "Time":"12 Jul 2016 930 AM EST " ,"Direction":"225" ,"Gusts":"2.4" ,"Wind":"1.7" ,"Tempature":"78.9" ,"KPTime":"2016-07-12 14:24" ,"KPCard":"SSW" ,"KPDirection":"202" ,"KPGusts":"7.00" ,"KPWind":"6.61" }

 

Then all you need to do in the condition is:

 

@greater(int(body('Http')['Gusts']), 5)

 

And then it'll work. I think the issues with the original post are:

1. You don't need to re-map anything in the HTTP call - just use the output-as is. The Body for that card should be the body you're passing to the backing API in the POST call -- so you should probably leave that blank (or provide whatever JSON that backing API requires in the POST).

2. The API is returning Gusts as a string, but you want to compare it as an integer. That means you have to use the int() function.

 

I hope this helps!

Kemedia
Frequent Visitor

How do you parse json to get the string from a HTTP POST.

 

I am working with the following response body:

 

Status Code: 200
Body: {"jsonrpc":"2.0","result":{"random":{"data":["48588608"],"completionTime":"2016-12-16 03:28:36Z"},"bitsUsed":27,"bitsLeft":249460,"requestsLeft":980,"advisoryDelay":230},"id":32400}

 

I want to extract the value 48588608 from result/random/data.

 

I am using Mcrosoft Flow and want to uise this string in an email, for example.

 

 

 

 

I'm now getting an error message:

'The template language expression 'greater(int(body('http')['Gusts']), 5)' cannot be evaluated because property 'Gusts' cannot be selected. Property selection is not supported on values of type 'String'. Please see https://aka.ms/logicexpressions for usage details.'.

Any thoughts how to debug this.  I'm really returning a Json string, not a well-formed http string.

The return string from the URL is:

{"Time":"December 16, 2016 10:00 am EST" ,"Card":"W" ,"Direction":"260" ,"Gusts":" 17.5" ,"Wind":" 13.6" ,"Tempature":" 20.7" ,"KPTime":"2016-12-16 15:12" ,"KPCard":"NW" ,"KPDirection":"325" ,"KPGusts":"17.88" ,"KPWind":"13.41" }

 

thanks

Andrew

I got the following to work for my Json:

 

@greater(float(json(body('http'))['Gusts']), 30)

 

in the condition and

 

Wind is @{json(body('http'))['Gusts']} from the @{json(body('http'))['Direction']} degrees from north

 

for the notification box.

 

Hope this helps

 

Andrew

Helpful resources

Announcements
PA 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

secondImage

Demo Extravaganza Winner Announcement

Please join us on Wednesday, July 21st at 8a PDT. We will be announcing the Winners of the Demo Extravaganza!

V3_PVA CAmpaign Carousel.png

Community Challenge - Giveaways!

Participate in the Power Virtual Agents Community Challenge

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Top Solution Authors
Top Kudoed Authors
Users online (2,270)