title: Iterate over JSON object with children
body: <p>I'm using fancytree to send data via ajax.</p>
  
  <pre><code>$("#save").click(function(e){
              e.preventDefault();
  
              var tree = $("#tree").fancytree("getTree").rootNode;
              var data = tree.toDict(true);
              data = JSON.stringify(data);
              $.ajax(
              { 
                  type: "POST",
                  data :  { "data": data },
                  contentType: "application/json",
                  success: function(data) {
                      $('#alert').empty().append(data);
                  }
              });
          });
  </code></pre>
  
  <p>The JSON data is the follwing format. I need to reiterate over the following JSON object inorder to manipulate the data.</p>
  
  <pre><code>{
  "expanded":true,
  "key":"root_1",
  "selected":false,
  "title":"root",
  "children":
  [
      {"key":"p_1","selected":false,"title":"Animal Meat"},
      {"key":"p_2","selected":false,"title":"Animal Product"},
      {"folder":true,"key":"p_3","selected":false,"title":"Beverage","children":  
      [
          {"key":"2","selected":false,"title":"Tea"},
          {"key":"3","selected":false,"title":"Coffee"},
          {"key":"4","selected":false,"title":"Water"}
      ]},
      {"folder":true,"key":"p_4","selected":true,"title":"Cereal","children": 
      [
          {"key":"6","selected":true,"title":"Porridge"}
      ]},
      {"folder":true,"key":"p_5","selected":false,"title":"Dairy Product","children":
      [
          {"key":"7","selected":false,"title":"Cheese"},
          {"key":"8","selected":false,"title":"Curd"},
          {"key":"10","selected":false,"title":"Milk"},
      ]}
  ]}
  </code></pre>
  
  <p>The following function in Laravel handles this request.</p>
  
  <pre><code>public function storePreference(Request $request)
      {
          $data = $request-&gt;getContent();
  
          $data = urldecode($data);
  
          foreach($data['children'] as $child)
          {
             $key      = $child['key'];
              $selected = $child['selected'];
              $title    = $child['title'];
  
              printf("Key: %s, selected: %s, title: %s\n", $key, $selected ? "true" : "false", $title);
          }
      }
  </code></pre>
  
  <p>I need the following output:</p>
  
  <pre><code>Key: p_1, selected: false, title: Animal Meat
  Key: p_2, selected: false, title: Animal Product
  Key: p_3, selected: false, title: Beverage
  Key: 2, selected: false, title: Tea
  Key: 3, selected: false, title: Coffee
  Key: 4, selected: false, title: Water
  Key: p_4, selected: true, title: Cereal
  Key: 6, selected: true, title: Porridge
  Key: p_5, selected: false, title: Dairy Product
  and so on...
  </code></pre>
  
  <p>I am using fancytree to send this data in Laravel 5.</p>
  
  <p>Any help would be much appreciated.</p>