I have a json file where just one of the fields so...
# nf-test
f
I have a json file where just one of the fields somehow gets shuffled by the tool I am using: The numbers that are being reported are the same but the order of fields changes and thus the assertion of the snapshot fails: Is there a way to handle this elegantly?
✅ 1
Like for example I could just exclude that key but I am not sure how I can exclude a key 😄
j
Can you use the built-in JSON parser to do stuff? https://www.nf-test.com/docs/assertions/files/?h=json#json-files
f
Thats what I am trying but so far I have not figured out how to exclude just one key (asserting just one key works) - i guess I am just missing the correct syntax
j
Does it return a map?
f
probably (internally)
j
Wonder if you can just recursively sort the map and then snapshot the whole thing (if the JSON is not too big)
f
the json is really small, I mean I would probably try sorting and then just get the md5 of the sorted json
but how do I sort it?
j
The basic pattern would be something like:
Copy code
def map = [c: 3, a: 1, b: 2]
map.sort { it.key }
👍 1
f
I think thats the right direction and it almost works - I think I just need to sort this one subkey - or rather figure out how to make the sort statement be applied to the subkeys as well
Or I just remove the key that causes the trouble with
Copy code
.findAll{it.key != "key"}
in any case: thank you the hint with the map was what did the trick!
🎉 1