title: Grails Creating JSON format output
body: <p>I'm writing a Grails web app to take the input data below and reformat it into the output format below that then can be used to draw fancyTree view. I created a controller class with the code shown in the except that follows. 
  How can I iterate through to make the format like the output format shown below?  I looked at how Groovy does each syntax but how can I use it to add ingredients?</p>
  
  <p><strong>code excerpt:</strong></p>
  
  <pre><code>def list(){
  
      def results = recipies.list()
  
      def recipiesContents = [:] //Test List
  
      recipiesContents=[] 
  
      for (record in results){
          test.add([folder:true, title: results.Name, key: results.key
          ])
      }
  
  
      //render response types
      withFormat {
          html test
          json {render test as JSON}
          xml {render test as XML}
      }
  }
  </code></pre>
  
  <p><strong>Input data:</strong></p>
  
  <pre><code>{
  recipies :[
  
  {key: "1",
  category:"Tuna Sandwich"
  data:[{some data}],
  ingredients: [
      {item_name:"mayo",
        brand: "My Own Brand"
      },
      {
        item_name: "Tuna".
        brand: "Bumble Bee"
      }
  ]},
  {key: "2",
  category:"Chicken Noodle Soup"
  data:[{some data}],
  ingredients: [
      {item_name:"condensed chicken soup",
        brand: "Campbell"
      },
      {
        item_name: "Noodles".
        brand: "Top Ramen"
      }
  ]}
  
  ]
  }
  </code></pre>
  
  <p><strong>output data:</strong></p>
  
  <pre><code>[
  {
      title: "Tuna Sandwich"
      ingredients: [
          {title: "Tuna"},
          {title: "mayo"}
      ]
  },
  {
      title: "Chicken Noodle Soup",
      ingredients: [
          {title: "condensed chicken soup"},
          {title: "Noodles"}
      ]
  }
  ]
  </code></pre>