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 / Get JSON key based on ...
Power Automate
Answered

Get JSON key based on value

(0) ShareShare
ReportReport
Posted on by 14

Hello there!

We have an inspection form that populates an excel spreadsheet (can't use MS Forms because the functions we need don't exist in it).  Answers are either "Pass" or "Fail".  I can get the latest entry using last():

last(body('List_rows_present_in_a_table')?['value'])

 Which returns the entire row as an object in JSON:

 

tjlyons65_0-1716586553946.png

 

The problem is, I need to extract only the  columns  that equal "Fail".  I've looked everywhere, and found lots of ways to pull the value based on the key, but not the other way around.  Do I have to use "Apply to Each", and if so, what would that look like?

Categories:
I have the same question (0)
  • Nived_Nambiar Profile Picture
    18,136 Super User 2026 Season 1 on at

    Hi @tjlyons65 

     

    There is no function which can help to get key value corresponding to value 

     

    So as a workaround try this approach

     

    Nived_Nambiar_0-1716646001567.png

     

    Get the last row based on above flow (same as your expression)

    last(outputs('List_rows_present_in_a_table')?['body/value'])
     
    Now use filter array to filter the key value pairs whose value is Fail as shown below
    Nived_Nambiar_1-1716646095532.png

     

    Expression - 

    split(replace(replace(string(outputs('Compose')),'{',''),'}',''),',')
    Nived_Nambiar_2-1716646152697.png

     

     

    Now once done with filtering, to extract the key values only - try this approach

    Nived_Nambiar_3-1716646201874.png

     

    Nived_Nambiar_4-1716646231055.png

     

    Expression - 

    replace(replace(split(item(),':')?[0],'"',''),'"','')
     
    Now see the output
     
    I have used the following excel table
    Nived_Nambiar_5-1716646264196.png

     

    Now see how select action result looks like

    Nived_Nambiar_6-1716646300314.png

     

    Hope this helps !

    Thanks & Regards,

    Nived N 🚀

    LinkedIn: Nived N's LinkedIn
    YouTube: Nived N's YouTube Channel
    Blog: Nived Nambiar's Blogs

    🔍 Found my answer helpful? Please consider marking it as the solution!
    Your appreciation keeps me motivated. Thank you! 🙌

     

  • VictorIvanidze Profile Picture
    13,079 on at

    Try this approach:

    VictorIvanidze_0-1716744966390.png

     

  • Verified answer
    Chriddle Profile Picture
    8,523 Super User 2026 Season 1 on at

    Another approach:

    Chriddle_0-1716758457562.png

    Compose

    {
    "Air filter": "Pass",
    "Oil filters": "Pass",
    "Body Damage": "Fail"
    }

     

    Select

    From

    xpath(
    	xml(json(concat('{"Root":{"Item":', outputs('Compose'), '}}'))),
    	concat('//Item/*[text()="Fail"]')
    )

    Map

    replace(
    	xpath(item(), 'name(/*)'),
    	'_x0020_',
    	' '
    )

    Chriddle_1-1716758569332.png

     

  • tjlyons65 Profile Picture
    14 on at

    Wow, thank you all!

  • tjlyons65 Profile Picture
    14 on at

    I don't understand it very well, but it works!  Thank you!

  • Chriddle Profile Picture
    8,523 Super User 2026 Season 1 on at

    In the Select's From, the object is conveted to XML and the xpath function returns an array of xml nodes that have the txt node "Fail" (//Item/*[text()="Fail"]).

     

    In the Map, the name of these items is determined (name(/*)) and '_x0020_' is replaced with a space.

    This is necessary because spaces are not allowed in XML node names and therefore encoded.

    If you encouter other special characters in your property names, check this post.

     

  • tjlyons65 Profile Picture
    14 on at

    Thank you!

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Leaderboard > Power Automate

#1
David_MA Profile Picture

David_MA 124 Super User 2026 Season 1

#2
Ellis Karim Profile Picture

Ellis Karim 52 Super User 2026 Season 1

#3
Haque Profile Picture

Haque 50

Last 30 days Overall leaderboard