arrange to_json #82

tejo opened this Issue Oct 31, 2011 · 5 comments


None yet

4 participants


Hi there,

I need to serialize an arranged tree of node to json format. If I call node.arrange.to_json I get something like:


this is because arrange returns an hash.

actually I can get this working looping through the hash and calling to_json for every node object.

There is a better way to do that?




Came here to see if anyone else is having this problem. My expereince is exactly the same as tejo's.


Same problem for me here using method as_json.


one user asked me how I managed to solve this problem.

basically I've added a recursive method like this in my model:

def self.json_tree(nodes) do |node, sub_nodes|
    {:name =>, :location => node.location, :date => node.published_date, :link => link, :id =>, :children => json_tree(sub_nodes, is_admin).compact } 

Then I simply call to_json to the returned nested hash

I send to this method is something like this:


Hope this can help.


Very helpful. Thanks a bunch.


I am also encountering this same issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment