title: How to create a JSON array as string from groovy objects?
body: <p>I have some data in Groovy's objects which I need to convert to a JSON string array. The final result should be..</p>
  <pre><code> [
        {
          &quot;keys&quot;:{
                   &quot;passcode&quot;: &quot;12345&quot;
                 },
          &quot;values&quot;:{
                    &quot;EmailAddress&quot;: &quot;john@doe.com&quot;,
                    &quot;message&quot;: &quot;Hello, is it me you are looking for?&quot;
                   }
        }
   ]
  </code></pre>
  <p>I found this <a href="https://stackoverflow.com/questions/13973342/how-to-use-groovy-builder-to-generate-an-array-type-json">post</a>  but the accepted answer which uses JSON Builder didn't make sense and the second answer using JSON converter didn't work...</p>
  <pre><code>def deJson = [
              keys: [
                      passcode: secretCode
              ],
              values: [
                      EmailAddress:emailData.to[0],
                      message: content.message
              ]
      ] as grails.converters.JSON
  </code></pre>
  <p>This created a JSON object when I needed an array.</p>
  <p>Can anyone suggest how I can use JSON Builder or JSON converter to create an array string like I have above?</p>