0

I have a JSON response that contains an array of buckets (and sub-buckets) and I want to assert that they're ordered alphabetically based on one of the properties in the bucket. I've tried the following:

String unsorted = new groovy.json.JsonSlurper().parseText(messageExchange.responseContent)
 ."data"
 .with { groovy.json.JsonOutput.toJson( it ) }
 
String sorted =  new groovy.json.JsonSlurper().parseText(messageExchange.responseContent)
 ."data"
 .sort { -it."foundPatientDisplayNaam" }
 .with { groovy.json.JsonOutput.toJson( it ) }
 
assert sorted == unsorted

But that gives me the following response:

No signature of method: java.lang.String.negative() is applicable for argument types: () values: []

Any ideas?

  • problem in minus `-` in this statement: `-it."foundPatientDisplayNaam"`. what is it doing there? – daggett Nov 07 '22 at 14:02
  • It's the property within the bucket that should be the basis for the order. I admit I "stole" this script and tried to apply it without understanding it fully. – Philip Stuij Nov 07 '22 at 14:10
  • By the way thanks, removing the minus seems to make the assertion work. The assertion fails but that may be legitimate. I'll take a closer look and mark the question answered when it all checks out. – Philip Stuij Nov 07 '22 at 14:15

1 Answers1

0

As pointed out by u/dagget, the script is fine except for the minus in this statement: -it."foundPatientDisplayNaam". Doh..