Skip to content
New issue

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

JSON.parse not compiling to a Tree::TreeNode #58

Closed
westlakem opened this issue May 17, 2016 · 3 comments · Fixed by #99
Closed

JSON.parse not compiling to a Tree::TreeNode #58

westlakem opened this issue May 17, 2016 · 3 comments · Fixed by #99
Assignees
Labels

Comments

@westlakem
Copy link

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

@evolve75 evolve75 added the Bug label May 20, 2016
@evolve75 evolve75 self-assigned this May 20, 2016
@westlakem
Copy link
Author

@evolve75 Any updates?

@alxppp
Copy link

alxppp commented Aug 27, 2016

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.

@VinceGuidry
Copy link

The core behavior in Ruby seems to have changed, use create_additions option on JSON.parse

      JSON.parse(str, create_additions: true)

evolve75 added a commit that referenced this issue Dec 27, 2023
…ect.

The `create_additions: true` option is **needed* for the parsing to work.

See issue <#58>.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants