I am new to Jolt.
Please how do I sort the following array in descending alphabetical order
Input :
[
{
"status": [
"ERROR",
"ERROR",
"REJECT",
"ERROR",
"ERROR",
"ERROR",
"ERROR"
]
}
]
I want status REJECT to be the first object, so the output is:
[
{
"status": [
"REJECT",
"ERROR",
"ERROR",
"ERROR",
"ERROR",
"ERROR",
"ERROR"
]
}
]
I have seen the jolt sort operation:
{
"operation": "sort"
}
But, how to I point it at the status array and also specify I need a descending sort please?
2
Answers
XPath 3.1 can do that:
Or with
Of course any XPath 3.1 solution can also be used in XSLT 3.0 or XQuery 3.1. I see you removed the xslt tag while I wrote the answer but I will post it as an alternative anyway.
If ascending order was the case, then you can easily match each components of the array with theirselves to make
"ERROR" : "ERROR"
and"REJECT" : "REJECT"
pairs within a shift transformation, and apply sort transformation.But, unfortunately there’s no direct method to get the descending order whereas a workaround might be given through reversely indexing the components of the array such as