title: Grails - Pass JSON/Map object to client
body: <p>I am trying to save a JSON object to a <code>data-</code> field in a gsp page.</p>
  
  <p>Mock controller:</p>
  
  <pre><code>def test(){
      ['comments': ["1": 1, "3":40 ] ] 
  }
  </code></pre>
  
  <p>GSP  (I also tried <code>(comments as JSON)</code> )</p>
  
  <pre><code>&lt;%@ page import="grails.converters.JSON" %&gt;
  &lt;div class='findme' data-comments="${comments as JSON}"&gt;
  </code></pre>
  
  <p>Result:</p>
  
  <pre><code>&lt;div class='findme' data-comments="{" 1":1,"3":40}"&gt;
  </code></pre>
  
  <p>As you can see the quotes are all messed up.  I tried using <code>encodeAsHTML</code> but it didn't work.</p>