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

3 REPLIES 3
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.

@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')

Thanks this worked perfectly for me.

Helpful resources

Announcements
Power Automate News & Announcements

Power Automate News & Announcements

Keep up to date with current events and community announcements in the Power Automate community.

Community Calls Conversations

Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Automate Community Blog

Power Automate Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Users online (3,593)