title: Working with JSONBuilder in Groovy/Grails
body: <p>As input I have list of all objects where each object has properties:</p>
  
  <ul>
  <li>name</li>
  <li>children(object.children is the list of all children)</li>
  <li>parent(null if object is top level)</li>
  </ul>
  
  <p>How correctly to use Groovy JSONBuilder to render such data(depth of tree is unlimited):</p>
  
  <pre><code>-Object 1
  --Object 1.1
  ---Object 1.1.1
  --Object 1.2
  -Object 2
  </code></pre>
  
  <p>in JSON format it should be something like this:</p>
  
  <pre><code>[
      {
          "name":"Object1",
          "children":[
              {
                  "name":"Object1.1",
                  "children":[
                      {
                          "name":"Object 1.1.1",
                          "children":[]
                      }
                  ]
              },
              {
                  "name":"Object1.2",
                  "children":[]
              }
          ]
      },
      {
          "name":"Object2","children":[]
      }
  ]
  </code></pre>
  
  <p>This is needed to build JSON for extJS component which will display this tree. Thanks for your help!</p>