Forum Discussion

kolersa's avatar
kolersa
Contributor
9 years ago

HOW CAN I CHECK WHAT OBLECTS IN JSON SORTED CORRECTLY BY SOME KEY?

How can I check what oblects in json sorted correctly by some key, I need something like this:

Assert what objects sorted by color in ABC order:
assert(isSort([{id:5, color:red}, {id:8, color:blue}{id:9, color:blue}{id:2, color:green}])) = false
assert(isSort([{id:9, color:blue}, {id:8, color:blue}{id:2, color:green}{id:5, color:red}])) = true

3 Replies

  • nmrao's avatar
    nmrao
    Champion Level 3
    Looks ids are in a map, you should be able get them to a list in order to sort.
    • kolersa's avatar
      kolersa
      Contributor

      But I need check what server sorted it correctly! I test API method what sort something.

      • nmrao's avatar
        nmrao
        Champion Level 3
        Well thats what the idea. So, get the ids in to a list. And do sort on the list. The trick is both list should be equal if response is already sorted, there would be no difference.