title: How to format json in rails controller?
body: <p>How to format json in rails controller? Via link_to i'm sending and get in method params[:cat], then i fetch all childrens via parent (params[:cat]), but how to format this all in json format for my jqTree? So it looks like {label : (here goes params[:cat]), children: [{all @search_trees.id}]} ? </p>
  
  <pre><code>require 'json'
          @search_trees = SearchTree.find(:all, :include =&gt; [:designation], :conditions =&gt; { :STR_ID_PARENT =&gt; params[:cat]})
          #data = "{ label : '10001',  children : [{label : '10111'},{label : '10122'}]  }"
          respond_to do |format|
            format.html # index.html.erb
            format.xml  { render :xml =&gt; @search_trees }
            format.json { render :json =&gt; data }
          end
  </code></pre>
  
  <p>I'll fetch a part of question from my long question here: </p>
  
  <blockquote>
    <p><a href="https://stackoverflow.com/questions/11728782/how-to-correctly-do-jquery-tree-in-rails-app">How to correctly do jquery tree in rails app?</a></p>
  </blockquote>
  
  <p>Her is my json:</p>
  
  <blockquote>
    <p>[{"search_tree":{"STR_DES_ID":42275,"STR_ID":10130,"STR_ID_PARENT":10726,"STR_LEVEL":4,"STR_NODE_NR":130,"STR_SORT":621,"STR_TYPE":1,"designation_id":42275}},{"search_tree":{"STR_DES_ID":42277,"STR_ID":10132,"STR_ID_PARENT":10726,"STR_LEVEL":4,"STR_NODE_NR":132,"STR_SORT":620,"STR_TYPE":1,"designation_id":42277}},{"search_tree":{"STR_DES_ID":43152,"STR_ID":10730,"STR_ID_PARENT":10726,"STR_LEVEL":4,"STR_NODE_NR":730,"STR_SORT":622,"STR_TYPE":1,"designation_id":43152}},{"search_tree":{"STR_DES_ID":42209,"STR_ID":12344,"STR_ID_PARENT":10726,"STR_LEVEL":4,"STR_NODE_NR":2344,"STR_SORT":623,"STR_TYPE":1,"designation_id":42209}}]
    i need to output like this
    <a href="https://stackoverflow.com/questions/10405222/jqtree-creating-tree-data-from-json">jqTree - creating tree data from json</a></p>
  </blockquote>