cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
saleelpk95
New Member

Use of Question Mark(?) in expressions

Could someone explain why some expressions contain a question mark in them while others not?

 

What is the difference between the two below?(Please note the '?' in the second one)

item()['some field']
item()?['some field']
1 ACCEPTED SOLUTION

Accepted Solutions
Pstork1
Dual Super User III
Dual Super User III

The use of the question mark in JSON specifies that if the field being referenced doesn't exist then a NULL value will be returned instead of throwing an error.  One of the common spots where you won't see the ? is when you are referencing a value that is part of an array.  For example

item()?['some field']['1']?['value field']

In this example 'some field' may or may not be returned as part of a JSON object.  If its not returned then a null will be returned if you try to use the value of the field.  But the field is supposed to be part of an array and we want the second element in the array. In the case of the index the value either exists or its an invalid array index, so we return an error rather than a null.

 



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

View solution in original post

2 REPLIES 2
Pstork1
Dual Super User III
Dual Super User III

The use of the question mark in JSON specifies that if the field being referenced doesn't exist then a NULL value will be returned instead of throwing an error.  One of the common spots where you won't see the ? is when you are referencing a value that is part of an array.  For example

item()?['some field']['1']?['value field']

In this example 'some field' may or may not be returned as part of a JSON object.  If its not returned then a null will be returned if you try to use the value of the field.  But the field is supposed to be part of an array and we want the second element in the array. In the case of the index the value either exists or its an invalid array index, so we return an error rather than a null.

 



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

View solution in original post

Thanks a lot!! That clarifies my doubt.

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Users online (1,279)