title: How to render JSON in Grails?
body: <p>I have an object as,</p>
  
  <pre><code>def roles = account.roles
  </code></pre>
  
  <p>I want to render it in JSON format like </p>
  
  <pre><code>[{'value':1, 'text':'Admin'},{'value':2,'text':'Owner'}, {'value':3,'text':'Sale'}]
  </code></pre>
  
  <p>When I did the code like this, it's not working,</p>
  
  <pre><code>render(contentType: "text/json"){[
      "value" : roles.id,
      "text" : roles.name
  ]}
  </code></pre>
  
  <p>It render to the data that has wrong format like <code>{"value":[1,2,3],"text":["Admin","Owner","Sale"]}</code></p>
  
  <p>And I try like this</p>
  
  <pre><code>def res = roles.each(){
      ['value':it.id, 'text':it.name]
  }
  render res as JSON
  </code></pre>
  
  <p>It's not working either.</p>