title: How to order a json output via groovy?
body: <p>I have seen something unusual with my SOAP UI script. I just want to perform an assertion that the data with is correct so I have written this code beLow:</p>
  
  <pre><code>import com.eviware.soapui.support.GroovyUtils
  import groovy.json.JsonOutput
  import groovy.json.JsonSlurper
  def response = messageExchange.response.responseContent
  def json =  new JsonSlurper().parseText(response)
  def jsonFormat = (response).toString()
  
  def policies = [
      [x: 28, xxx: 41, xxxxx: 1, name: 'Individual 18-50', aaa: true], 
      [x: 31, xxx: 41, xxxxx: 1, name: 'Individual 51-60', aaa: true], 
      [x: 34, xxx: 41, xxxxx: 1, name: 'Individual 61-75', aaa: true], 
      [x: 37, xxx: 41, xxxxx: 1, name: 'Individual 76-85', aaa: false]
  ]
  
  log.warn json.policies
  log.error policies
  assert json.policies == policies
  </code></pre>
  
  <p>When I look at the log.warn and log.error info, it displays the json response in the incorrect order as it display 'isActive' field first. </p>
  
  <p>log.warn <code>json.policies</code> displays this:</p>
  
  <pre><code>[{aaa=true, xx=28, xxxxx=1, name=Individual 18-50, xxxx=41}, {aaa=true, x=31, xxxxx=1, name=Individual 51-60, xxx=41}, {aaa=true, x=34, xxxxx=1, name=Individual 61-75, xxx=41}, {aaa=true, x=37, xxxxx=1, name=Individual 76-85, xxx=41}]
  </code></pre>
  
  <p>log.error <code>policies</code> displays this:</p>
  
  <pre><code>[{x=28, xxx=41, xxxxx=1, name=Individual 18-50, aaa=true}, {x=31, xxx=41, xxxxx=1, name=Individual 51-60, aaa=true}, {x=34, xxxx=41, xxxxxx=1, name=Individual 61-75, aaa=true}, {x=37, xxx=41, xxxxx=1, name=Individual 76-85, aaa=false}]
  </code></pre>
  
  <p>How can I have the DTOs to be displayed within the correct order with <code>json.policies</code> so that it is displayed in the correct order as policies?</p>
  
  <p>One more unusual thing, I ran the test case 10 times and the test step which this assertion checks has passed 3 out of 10 times. It should never have passed as if you compare the last DTO as the end for <code>policies</code>, it displays <code>isActive</code> as <em>false</em> which the last isActive in <code>json.policies</code> is <em>true</em>.</p>