title: How do I compare JSON in a grails test
body: <p>I have a controller in Grails that is returning a response in JSON.</p>
  
  <p>I have written a test which works roughly like this</p>
  
  <pre><code>test(){
       def expectedResponse=JSON.parse('[{"username":"user","startDate":"2010-11-30"}]')
      ...
              def actualResponse=JSON.parse(response.text)
  
              println "Expecting: ${expectedResponse.toString()}"
              println "Actual: ${actualResponse.toString()}"
  
              assertEquals(expectedResponse.toString(), actualResponse.toString())
      ...
          }
  </code></pre>
  
  <p>This works as expected</p>
  
  <pre><code>Expecting: [{"username":"user","startDate":"2010-11-30"}]
  Actual: [{"username":"user","startDate":"2010-11-30"}]
  </code></pre>
  
  <p>However, I was wondering if there was a better way to do this without resorting to a string comparison.. Perhaps something that could leave me the flexibility to be able to add attributes to the response without invalidating my test case?</p>
  
  <p>I could build this myself, but I would've expected some sort of JSON comparison to be built into the language.</p>
  
  <p>Update:
  I tried doing this directly, without the toString and have had inconsistent results, not quite sure why, it was working at one stage then suddenly got this. I can't see any code changes I made that would've caused the difference</p>
  
  <pre><code>groovy.lang.MissingMethodException: No signature of method: com.siggysale.MainControllerTests.assertEquals() is applicable for argument types: (org.codehaus.groovy.grails.web.json.JSONArray, org.codehaus.groovy.grails.web.json.JSONArray) values: [[], []]
  </code></pre>