dewski / json_builder

Rails provides an excellent XML Builder by default to build RSS and ATOM feeds, but nothing to help you build complex and custom JSON data structures. JSON Builder is here to help.
http://garrettbjerkhoel.com/json_builder/
MIT License
243 stars 52 forks source link

Decimals in hashes disappear. #22

Closed woodardj closed 12 years ago

woodardj commented 12 years ago

When adding a hash including a floating point value to the generator, it disappears in the resulting json.

Not the same as issue 2!

> h = {"hello" => 1.4}
=> {"hello"=>1.4}
> json = JSONBuilder::Generator.new 
=> {}
> json.data h
=> ["\"data\": {\"hello\": }"]
> json.compile!
=> "{\"data\": {\"hello\": }}"
dewski commented 12 years ago

Which version of the gem are you using? This is an older version of the gem that had quite a few bugs like this. I'd suggest upgrading to json_builder 3.1.0.

irb(main):007:0> JSONBuilder::Compiler.generate do
irb(main):008:1*   data({"hello" => 1.4})
irb(main):009:1> end
=> "{\"data\": {\"hello\":1.4}}"
woodardj commented 12 years ago

Nope, you're right! Miscommunication with my team around our Gemfile. Thanks for the quick reply!

dewski commented 12 years ago

No problem, let me know if you need any more help!