Sort object using SORT_BY_KEY

I have an object:

[{“Startnummer”:1,“fields”:{“Song”:"#fuori c’è il sole",“Interpret”:“Lorenzo Fragola”,“Platztipp”:21},“id”:“0”},{“Startnummer”:2,“fields”:{“Song”:“Englishman in New York”,“Interpret”:“Sting”,“Platztipp”:21},“id”:“1”},{“Startnummer”:3,“fields”:{“Song”:“Travelin Band”,“Interpret”:“Clarence Clearw. Rev.”,“Platztipp”:21},“id”:“2”},
{“Startnummer”:4,“fields”:{“Song”:“Route 66”,“Interpret”:“Rolling Stones”,“Platztipp”:21},“id”:“3”}]

I am trying to sort this object by “Platztipp”.

I have tried SORT_BY_KEY(appVars.SongPlatz,“fields.Platztipp”) and SORT_BY_KEY(appVars.SongPlatz.“Platztipp”) with an without quotes to no avail.

Any hint how i can sort this? Examples for how SORT_BY_KEY can be used in more complex objects would be great.

Cheers and thank you very much in advance.

Using SORT_BY_KEY(appVars.SongPlatz, "fields.Platztipp") would sort by item["fields.Platztipp"] (not the same as item.fields.Platztipp) for each array item, so you cannot use the dot notation to traverse the object that way.

The best option would be to use ORDER, which is a higher-order formula where the sorting predicate is also a formula expression instead of just a field name. This should be pretty straightforward with that formula, something like:

ORDER<item>(appVars.SongPlatz, item.fields.Platztipp, "asc")

2 Likes

Dream come true! Works like a Bomb.
Thank you very much for the super speedy solution.
Two thumbs up.

@Pekka_Aaltonen , thank you for the solution

3 questions to help me and anyone who finds this post.

  1. what is the difference between

item[“fields.Platztipp”]
vs
item.fields.Platztipp

to access a nested array we would do something like testArray[0][1] right, so what is the meaning of item[“fields.Platztipp”]?

  1. this is your solution → ORDER(appVars.SongPlatz, item.fields.Platztipp, “asc”)

what is the right after ORDER for? i tried removing the “” and it still works fine.

  1. this is a documentation question → how would a hardworking noob like myself find the word “item”? as per the below screenshot, “item” does not belong to any group so me going through all the Variables and Functions, i still wouldn’t be able to find it.

at least for “self”, when i click on “Selected component properties” on the left side bar, i can see “self.id”

but i can’t find “item” anywhere

image