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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Check if Object Key Ex...
Power Automate
Answered

Check if Object Key Exists

(1) ShareShare
ReportReport
Posted on by 19
How can I check if an object does have a certain key inside? Like checking if objectX.keyY exists and not null.
 
I have the same question (0)
  • Suggested answer
    eetuRobo Profile Picture
    4,222 Super User 2025 Season 2 on at
    You could do condition that checks if the object contains the key as text. 



    But that would also be true if there isn't "includesCobra" key but a value like that.

    You can use On block error to continue the flow even if error happens.



    So you would have set variable to get the value of certain key in that object. Then if it doesn't exist error happens but On block lets the flow continue.



    If the key was not in the object then the variable will be empty. And if its not empty then the key was in the object
  • AH-28020957-0 Profile Picture
    19 on at
    I have many fields I need to check, do we really need to end up with this complicated flow for it? Don't we have an easier solution?
  • Suggested answer
    eetuRobo Profile Picture
    4,222 Super User 2025 Season 2 on at
    One bit hacky way could be to convert the object to JSON and then do the checks to see if the json contains: "Key":"
    So if I want to check if my object has the key "FirstName" then I check if the json contains: "FirstName":"

    Like so:


    This should only match the keys and not values.

    Or final way would be to create a script that checks if the object contains the key. I don't know any cleaner ways than these sorry.
  • Verified answer
    Riyaz_riz11 Profile Picture
    3,893 Super User 2025 Season 2 on at
    HI,
     

    Basic Key Existence Check

    Action: If
    Condition: %Contains(objectX, "keyY")%
    Operation: Equal to (=)
    Second operand: True

    Key Exists AND Not Null Check

    Action: If
    Condition: %Contains(objectX, "keyY") AND objectX["keyY"] <> $null%
    Operation: Equal to (=)
    Second operand: True

    Complete Expression for Your Use Case

    First operand: %Contains(objectX, "keyY") AND objectX["keyY"] <> $null AND objectX["keyY"] <> ""%
    Operator: Equal to (=)
    Second operand: true

    Method 2: Using Try-Catch Pattern

    Set up Try-Catch with Variables

    # Initialize variable
    VARIABLE %KeyExists% VALUE: False
    
    # Try block
    BEGIN TRY
        SET %TestValue% TO %objectX["keyY"]%
        IF %TestValue% <> $null THEN
            SET %KeyExists% TO True
        END IF
    END TRY
    
    # Catch block  
    BEGIN CATCH
        SET %KeyExists% TO False
    END CATCH
    
    # Use in condition
    IF %KeyExists% = True THEN
        # Key exists and is not null
    END IF
     
    If I have answered your question, please mark it as the preferred solution ✅ . If you like my response, please give it a Thumbs Up 👍.
    Regards,
    Riyaz
     
  • AH-28020957-0 Profile Picture
    19 on at
    The first basic check works, but the second null checker is having a syntax error, I think because of $null.. 

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 478 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 247 Moderator

#3
abm abm Profile Picture

abm abm 231 Most Valuable Professional

Last 30 days Overall leaderboard