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 / Order array (JSON) by ...
Power Automate
Unanswered

Order array (JSON) by field value (date)

(0) ShareShare
ReportReport
Posted on by 10

Hi there, I am trying to order by "start_time" a JSON object with the following structure:

 

{
 "Events": [
 {
 "id": "1",
 "start_time": "2023-11-26T03:00:00Z" 
 },
 {
 "id": "2",
 "start_time": "2023-11-26T02:00:00Z" 
 }
 ]
}

 

 

I've tried doing it with PA Desktop's Javascript scripting but cannot wrap my head around it (cannot use basic JS syntax like "const", cannot return the entire array with WScript.echo() , ...)

Any idea of how to do this? I am fine with either PA Desktop or PA Cloud solutions, whatever is more performant and easy to implement.

Cheers. 

 

I have the same question (0)
  • Rhiassuring Profile Picture
    8,692 Moderator on at

    sort(variables('objYourObjectHere')?['Events'],'Start_Time')

     

    Need to call out where the arrays are (in "Events" object), and then what value you want to sort by.

     

    If you want it reversed, you can wrap it in reverse().

  • yoko2020 Profile Picture
    495 on at

    Powershell in PAD

    # Your JSON string
    $jsonString = '{
     "Events": [
     {
     "id": "1",
     "start_time": "2023-11-26T03:00:00Z" 
     },
     {
     "id": "2",
     "start_time": "2023-11-26T02:00:00Z" 
     }
     ]
    }'
    
    # Convert JSON string to PowerShell object
    $jsonObject = ConvertFrom-Json $jsonString
    
    # Sort the "Events" array based on the "start_time" property
    $sortedEvents = $jsonObject.Events | Sort-Object start_time
    
    # Update the sorted array back to the original object
    $jsonObject.Events = $sortedEvents
    
    # Convert the updated object back to JSON string
    $sortedJsonString = $jsonObject | ConvertTo-Json -Depth 100
    
    # Display the sorted JSON string
    Write-Host $sortedJsonString
  • Agnius Bartninkas Profile Picture
    Most Valuable Professional on at

    Use Convert JSON to custom object if it's not converted yet. Then use Sort list and sort %JsonAsCustomObject['Events']%. 

     

    Under Advanced options, enable the "Sort list by items' properties" toggle and provide the specific property you want to sort by - in your case "start_time".

    -------------------------------------------------------------------------

    If I have answered your question, please mark it as the preferred solution. If you like my response, please give it a Thumbs Up.

     

    I also provide paid consultancy and development services using Power Automate. If you're interested, DM me and we can discuss it.

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!

Congratulations to the April Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Vish WR Profile Picture

Vish WR 796

#2
Valantis Profile Picture

Valantis 568

#3
Haque Profile Picture

Haque 538

Last 30 days Overall leaderboard