title: Grails GSON JSON views
body: <p>I want to generate JSON output similar to this one:</p>
  
  <pre><code>var json = {
          id: "1",
          name: "AAA",
          children: [{
              id: "2",
              name: "BBB",
              data: {
                  relation: "&lt;b&gt;Connections:&lt;/b&gt;&lt;ul&gt;&lt;li&gt; AAA &lt;div&gt;(relation: direct)&lt;/div&gt;&lt;/li&gt;&lt;li&gt; CCC &lt;div&gt;(relation: direct)&lt;/div&gt;&lt;/li&gt;&lt;/ul&gt;"
              },
              children: [{
                  id: "3",
                  name: "CCC",
                  data: {
                      relation: "&lt;b&gt;Connections:&lt;/b&gt;&lt;ul&gt;&lt;li&gt; BBB &lt;div&gt;(relation: direct)&lt;/div&gt;&lt;/li&gt;&lt;/ul&gt;"
                  },
                  children: []
              }]
          }, ....
  </code></pre>
  
  <p>Here is what I did so far:</p>
  
  <pre><code>grails create-domain-resource json.Object
  </code></pre>
  
  <hr>
  
  <pre><code>class Object{
      String name
      String relation
      static hasMany = [children: Object]
  
      public String getData() {
          def writer = new StringWriter()
  </code></pre>
  
  <p>_object.gson</p>
  
  <hr>
  
  <pre><code>//json g.render(hero)
  json {
      //data hero.data
      data: {relation hero.relation}
      name hero.name
  }
  </code></pre>
  
  <p>Problem
  I'm not able to produce:</p>
  
  <pre><code> data: {
                      relation: "&lt;b&gt;Connections:&lt;/b&gt;&lt;ul&gt;&lt;li&gt; BBB &lt;div&gt;(relation: direct)&lt;/div&gt;&lt;/li&gt;&lt;/ul&gt;"
                  },
  </code></pre>
  
  <p>Questions:
  1) I've read the official documentation but I'm not able to find how to do transient fields
  2) What is best approach of mixing json and xml / html.
  3) How to pass json code to another view variable</p>
  
  <p>thank you in advance</p>