cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
dcafiero
Regular Visitor

Handling if a key does not exist in JSON Parse

I am working with some data from an API where need to look at some values from a JSON file. I am using the apply each and then using compose to get the values of an array. Unfortunately, some of the keys I am looking for do not exist so Power Automate is failing. 

 

Is there a way that if it fails that it returns a null value??? 

 

In the Inputs for the compose I am using variables('trackerRows').cells[7].value).
 
The problem is on some of the elements, value does not exist as a field in the json for some of the values. Is there a way to ignore this somehow or should I take a different approach?
 
So Microsoft flow returns a message like this:
 
InvalidTemplate. Unable to process template language expressions in action 'ExecutiveSponsor' inputs at line '1' and column '2906': 'The template language expression 'variables('trackerRows').cells[9].value' cannot be evaluated because property 'value' doesn't exist, available properties are 'columnId'. Please see https://aka.ms/logicexpressions for usage details.'
 
 
 
1 ACCEPTED SOLUTION

Accepted Solutions
v-litu-msft
Community Support
Community Support

Hi @dcafiero,

 

You could use Parse JSON action to parse these data, then you could use dynamic content in next actions.

I use an instance to explain, I have a JSON as below, the Age property is not required, some item does not contain it. Then put the "Name" array into Apply to each action, if the Age property does not exist in the item, it will return null:

Annotation 2020-06-18 142425.jpg

 

Best Regards,
Community Support Team _ Lin Tu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
v-litu-msft
Community Support
Community Support

Hi @dcafiero,

 

You could use Parse JSON action to parse these data, then you could use dynamic content in next actions.

I use an instance to explain, I have a JSON as below, the Age property is not required, some item does not contain it. Then put the "Name" array into Apply to each action, if the Age property does not exist in the item, it will return null:

Annotation 2020-06-18 142425.jpg

 

Best Regards,
Community Support Team _ Lin Tu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

@v-litu-msft,

 

I will try what you mentioned. 

 

I was able to handle this for the time being by in my compose adding an if statement if it doesn't contain a value to return null.

 

if(contains(variables('trackerRows').cells[9], 'value'), variables('trackerRows').cells[9].value, 'null')

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

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.

Users online (2,955)