cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
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
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
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
PP Bootcamp Carousel

Global Power Platform Bootcamp

Dive into the Power Platform stack with hands-on sessions and labs, virtually delivered to you by experts and community leaders.

secondImage

Power Platform Community Conference On Demand

Watch Nick Doelman's session from the 2020 Power Platform Community Conference on demand!

MPA Community Blog

Power Automate Community Blog

Check out the community blog page where you can find valuable learning material from community and product team members!

Top Solution Authors
Users online (8,273)