We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Title says it all, JSON.parse is returning the default hash instead of tree
json file
{ "name": "ROOT", "content": null, "json_class": "Tree::TreeNode", "children": [ { "name": "NON-ROOT", "content": null, "json_class": "Tree::TreeNode", "children": [ { "name": "NON-ROOT-2", "content": null, "json_class": "Tree::TreeNode" } ] } ] }
r = JSON.parse(File.read('config/routes.json'))
=> {"name"=>"ROOT", "content"=>nil, "json_class"=>"Tree::TreeNode", "children"=>[{"name"=>"NON-ROOT", "content"=>nil, "json_class"=>"Tree::TreeNode", "children"=>[{"name"=>"NON-ROOT-2", "content"=>nil, "json_class"=>"Tree::TreeNode"}]}]}
r.class
=> Hash
rubytree version 0.9.7 JSON version 1.8.3 on JRUBY 9.0.5.0
The text was updated successfully, but these errors were encountered:
@evolve75 Any updates?
Sorry, something went wrong.
I am using this as a workaround:
def load_tree(json_hash) node = Tree::TreeNode.new(json_hash['name'], json_hash['content']) json_hash['children'].each { |h| node << load_tree(h) } unless json_hash['children'].nil? node end
I guess the performance is terrible but it's working well enough for me with a tree < 10,000 leafs.
The core behavior in Ruby seems to have changed, use create_additions option on JSON.parse
create_additions
JSON.parse
JSON.parse(str, create_additions: true)
Clarified the comment for parsing a string or hash back to a tree obj…
9e7fc33
…ect. The `create_additions: true` option is **needed* for the parsing to work. See issue <#58>.
create_additions: true
evolve75
Successfully merging a pull request may close this issue.
Title says it all, JSON.parse is returning the default hash instead of tree
json file
r = JSON.parse(File.read('config/routes.json'))
=> {"name"=>"ROOT", "content"=>nil, "json_class"=>"Tree::TreeNode", "children"=>[{"name"=>"NON-ROOT", "content"=>nil, "json_class"=>"Tree::TreeNode", "children"=>[{"name"=>"NON-ROOT-2", "content"=>nil, "json_class"=>"Tree::TreeNode"}]}]}
r.class
=> Hash
rubytree version 0.9.7
JSON version 1.8.3
on JRUBY 9.0.5.0
The text was updated successfully, but these errors were encountered: