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 / Sort JSON array by key
Power Automate
Unanswered

Sort JSON array by key

(1) ShareShare
ReportReport
Posted on by 6

Hi there,

 

I am using the action "Parse JSON" in my Flow and would like to sort the results by a specific key.

 

So, in the following example I want to sort elements by "SubscriptionName". Can anyone help me to find the correct answer and tell me where to insert by sort function into the following code?

 

Thx in advance

Dorothee

 

{
    "type""array",
    "items": {
        "type""object",
        "properties": {
            "Charge DateDif": {
                "type""integer"
            },
            "ChargeEndDate": {
                "type""string"
            },
            "ChargeStartDate": {
                "type""string"
            },
            "CustomerID": {
                "type""string"
            },
            "Id": {
                "type""string"
            },
            "IdRechnungsnummer": {
                "type""string"
            },
            "MailSent": {
                "type""string"
            },
            "Quantity": {
                "type""integer"
            },
            "Source.Name": {
                "type""string"
            },
            "SubscriptionName": {
                "type""string"
            },
            "VK": {
                "type""number"
            },
            "Auftragsnummer": {
                "type""string"
            },
            "CustomerName": {
                "type""string"
            }
        },
        "required": [
            "Auftragsnummer",
            "Charge DateDif",
            "ChargeEndDate",
            "ChargeStartDate",
            "CustomerID",
            "CustomerName",
            "Id",
            "IdRechnungsnummer",
            "MailSent",
            "Quantity",
            "Source.Name",
            "SubscriptionName",
            "VK"
        ]
    }
}
Categories:
I have the same question (0)
  • Verified answer
    v-litu-msft Profile Picture
    on at

    Hi @Dorothee123,

     

    It's unfortunate insert in order function into the schema is not supported on Power Automate yet.

    As a workaround, there is a blog that sorts an array by building an expression:

    https://sharepains.com/2019/07/13/sort-an-array-or-collection-in-microsoft-flow/

     

    Best Regards,
    Community Support Team _ Lin Tu
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

  • Dorothee123 Profile Picture
    6 on at

    Thanks @v-litu-msft for your quick reply

  • Jnas Profile Picture
    30 on at

    By now there is a way to sort JSON arrays by a key: Just add a new compose action and use the sort() function.

    To sort by the key "SubscriptionName", one would use the following code:

    sort(body('NameOfPreviousJSONAction'),'SubscriptionName').

    Just replace NameOfPrevoiusJSONAction with your preceding JSON action. The default order of the sort() function seems to be ascending.

    Below is an example from a flow of mine. I sorted my JSON array by the key "KST".

    Jnas_0-1716395854141.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

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 522 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 364 Moderator

#3
abm abm Profile Picture

abm abm 243 Most Valuable Professional

Last 30 days Overall leaderboard