Skip to main content

Notifications

Community site session details

Community site session details

Session Id : bGKxPLhrs31XzdBBmr3s7Y
Power Automate - Building Flows
Answered

How do I get a property from a JSON object?

Like (1) ShareShare
ReportReport
Posted on 24 Feb 2025 21:09:59 by 3
Hi there, 
 
I am pretty new to Power Automate. 
 
I have this JSON response from an API call. It is an object of objects.
 
{
  "created_at": "2025-02-24 09:20:30",
  "status": "ACTIVE",
  "new": "0",
  "flag": "0",
  "notes": "",
  "updated_at": "2025-02-24 09:20:30",
  "answers": {
    "157": {
      "name": "OK",
      "order": "14",
      "text": "Are you OK to answer this question?",
      "type": "ctl_radio",
      "answer": "No"
    },
    "158": {
      "name": "submission",
      "order": "1",
      "sublabels": "{\"day\":\"Day\",\"hour\":\"Hour\",\"last\":\"Last\",\"litemode\":\"Date\",\"minutes\":\"Minutes\",\"month\":\"Month\",\"year\":\"Year\"}",
      "text": "Submission",
      "timeFormat": "24 Hour",
      "type": "control_datetime"
    },
    "150": {
      "name": "date",
      "order": "5",
      "sublabels": "{\"day\":\"Day\",\"month\":\"Month\",\"year\":\"Year\",\"last\":\"Last Name\",\"hour\":\"Hour\",\"minutes\":\"Minutes\",\"litemode\":\"Date\"}",
      "text": "Date",
      "timeFormat": "AM/PM",
      "type": "control_datetime",
      "answer": {
        "month": "02",
        "day": "23",
        "year": "2025",
        "datetime": "2025-02-23 00:00:00"
      },
      "FormattedDate": "02-23-2025"
    }
  }
}
 
How can I get just the 'FormattedDate' part in a Compose action using an expression (or anything)? 
 
The reason I am struggling is that whilst "FormattedDate" is always within the final object of the response, the title of this object (e.g. "150" in the above) will change. The only constants to work with are that the text property will always be "Date" and the name property will always be "date". 
 
Is there anyway to get this value? I am looking to simply extract it as a string in a Compose action, and I can format it later on from there. 
 
Cheers very much
BC Jabra.
 
 
 
  • Verified answer
    Chriddle Profile Picture
    7,708 Super User 2025 Season 1 on 25 Feb 2025 at 07:34:25
    How do I get a property from a JSON object?
    Assuming your JSON is in a Compose, all you need is this simple XPath expression:
    xpath(
    	xml(json(concat('{"Root":{"Item":', outputs('Compose'), '}}'))),
    	'//Item/answers/*[text="Date"]/FormattedDate/text()'
    )
    This returns a list of values. Just take the first one.
  • Suggested answer
    Michael E. Gernaey Profile Picture
    42,060 Super User 2025 Season 1 on 25 Feb 2025 at 00:27:15
    How do I get a property from a JSON object?
     
    A very simple way is to extract it directly using a few expressions in your compose. I am showing you this as it will also help you in other areas besides this, as a lesson.
     
    1. I have your Object (and copied yours out)
    2. I add a Compose
    I use the following to get the date value itself.
    split(split(trim(string(variables('JsonData'))),'"FormattedDate":"')[1], '"}')[0]
    now let me explain it.
    --I have a Variable (object) I created in my flow and pasted in your data. I called the Variable JsonData.
    ----Next, I have to use the string and trim functions to change the object into a string and to remove all spaces as you see below
    {"created_at":"2025-02-24 09:20:30","status":"ACTIVE","new":"0","flag":"0","notes":"","updated_at":"2025-02-24 09:20:30","answers":{"150":{"name":"date","order":"5","sublabels":"{\"day\":\"Day\",\"month\":\"Month\",\"year\":\"Year\",\"last\":\"Last Name\",\"hour\":\"Hour\",\"minutes\":\"Minutes\",\"litemode\":\"Date\"}","text":"Date","timeFormat":"AM/PM","type":"control_datetime","answer":{"month":"02","day":"23","year":"2025","datetime":"2025-02-23 00:00:00"},"FormattedDate":"02-23-2025"},"157":{"name":"OK","order":"14","text":"Are you OK to answer this question?","type":"ctl_radio","answer":"No"},"158":{"name":"submission","order":"1","sublabels":"{\"day\":\"Day\",\"hour\":\"Hour\",\"last\":\"Last\",\"litemode\":\"Date\",\"minutes\":\"Minutes\",\"month\":\"Month\",\"year\":\"Year\"}","text":"Submission","timeFormat":"24 Hour","type":"control_datetime"}}}
     
    ----Next, I use split to take the full string and turn it into 2 halves, by splitting by 
    "FormattedDate":" and I use the [1] to tell the Split command, to give me back the 2nd value in the returned split array
    Since split gives an array back, we don't want the front part (aka [0]) we want the back part (aka [1])
     
    ----Next, we take the back part which looks like this
    02-23-2025"},"157":{"name":"OK","order":"14","text":"Are you OK to answer this question?","type":"ctl_radio","answer":"No"},"158":{"name":"submission","order":"1","sublabels":"{\"day\":\"Day\",\"hour\":\"Hour\",\"last\":\"Last\",\"litemode\":\"Date\",\"minutes\":\"Minutes\",\"month\":\"Month\",\"year\":\"Year\"}","text":"Submission","timeFormat":"24 Hour","type":"control_datetime"}}}
     
    You can see 02-23-2025"} at the start.
    well we want to use Split again so that we can get the date value. Use the split function with value "} because its what comes right after the actual date value we want.
     
    So now in the Second split array, we get the Date which sits in the [0] split and then the rest of the object data string is in [1] which we don't care about.
     
    And a visually formatted so it flows with the expressions I showed above
     
     split(
          split(
               trim(
                     string(variables('JsonData'))
                )
          ,'"FormattedDate":"')[1]
    , '"}')[0]
  • Suggested answer
    rzaneti Profile Picture
    4,028 Super User 2025 Season 1 on 24 Feb 2025 at 23:26:26
    How do I get a property from a JSON object?
     
    For the specific example, you can use an expression like [your_json_outputs]['150']['FormattedDate'], but I believe you already know about it :)
     
    To solve your problem, you would need to first retrieve the last key from a JSON object, so you can use it as a substitute for the 150 in the expression above. There is not a built-in function or action to retrieve the last key, but you can use a workaround with the xpath function. In this blog, you can find a step-by-step to retrieve all keys from a JSON object: https://digitalmill.net/2024/10/03/extracting-json-object-keys-in-power-automate/
     
    Then you can reference the last one by using the last() function. Finally, your ideal expression may look like: [your_json_outputs][last([lkeys_arr])]['FormattedDate'], where the dynamic content of the array generated from the object keys corresponds to the text in red.
     
    If the instructions are not clear enough, I will be happy to provide you further guidance. 
     
    Let me know if it works for you or if you need any additional help!
     
    If this is the answer to your question, please mark the post as Accepted Answer.
    If this answer helps you in any way, please give it a like.

    Check more Power Platform content on my website.
    Lets connect on LinkedIn.

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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Power Automate - Building Flows

#1
stampcoin Profile Picture

stampcoin 105

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 84 Super User 2025 Season 1

#3
David_MA Profile Picture

David_MA 62 Super User 2025 Season 1

Overall leaderboard
Loading started