web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Use of Question Mark(?...
Power Automate
Answered

Use of Question Mark(?) in expressions

(5) ShareShare
ReportReport
Posted on by 15

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']
Categories:
  • Verified answer
    Pstork1 Profile Picture
    69,665 Most Valuable Professional on at

    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.

     

  • saleelpk95 Profile Picture
    15 on at

    Thanks a lot!! That clarifies my doubt.

  • ANCC Profile Picture
    23 on at

    The first part of that made sense and then it was just words. I understand the use of question marks sometimes (optional parameters), but I am still not quite understanding it's use in an array, as I do not entirely understand JSON. Can anyone expand?

  • Pstork1 Profile Picture
    69,665 Most Valuable Professional on at

    The ['1'] in the example I gave is the integer index to the array item.  In regular programming languages it is common to reference the entries in an array using an integer index, like A(0), A(1), A(2), etc.  This is just the JSON version of that encoding.

  • HaroldA Profile Picture
    96 on at

    This is so confusing.  Is the structure of the language documented anywhere?  I am an experienced programmer, but it is very difficult to write code by guessing what the syntax is.  I don't even understand what item() means or why you need single quotes to get the first item in an array.

  • Pstork1 Profile Picture
    69,665 Most Valuable Professional on at

    The syntax is just JSON Object notation.  You can find a variety of web resources that teach JSON.

     

    Item() in this case is the current item in an Apply to each loop.  So Item()['Title'] means the Title property of the current item in the loop.  When you see the question mark between them it means the following property is optional and may not exist.  If it doesn't return a null.  So 

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

    is

    item() - the current item in the loop

    ?['some field'] - an optional property of the item.  In this case its an array

    ['1'] - the first array item of that optional property

    ?['Value field'] - a property of the first array item 

  • HaroldA Profile Picture
    96 on at

    JSON doesn't have parentheses or question marks.  I think it might be Javascript. @Pstork1 

    I'll have to figure out how to write it in order to use Power Automate.  Javascript was not required to write the custom connector.

  • Pstork1 Profile Picture
    69,665 Most Valuable Professional on at

    JSON is "JavaScript Object Notation", so yes it is Javascript.  JSON itself doesn't make use of parentheses or ?, but the syntax for identifying the path to JSON objects, arrays, and properties does.

  • Pstork1 Profile Picture
    69,665 Most Valuable Professional on at

    This blog post may help as an introduction to the notation.  How to get a specific value from a JSON in Power Automate (tomriha.com)

  • HaroldA Profile Picture
    96 on at

    Why is this happening?

    Harold_Anderson_0-1645037140608.png

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Automate

#1
11manish Profile Picture

11manish 321 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 244

#3
Henil Profile Picture

Henil 102

Last 30 days Overall leaderboard