I have used sort, but sort removes the key value of the json document. The sort function replaces the key with a number:
range $key, $value := .Data.document
In this case I get in $key, the json key values but in
range $key, $value := sort .Data.document "group"
I get in $key a number in [0, number of objects), so I lost the key. I have put inside the $value the key also and so I can solve the problem