Nils Nils - 10 months ago 37
Ruby Question

JSON object for just an integer

Silly question, but I'm unable to figure out..

I tried the following in Ruby:

irb(main):020:0> JSON.load('[1,2,3]').class
=> Array

This seems to work. While neither


nor this


works. Any ideas?


I'd ask the guys who programmed the library. AFAIK, 1 isn't a valid JSON object, and neither is {1} but 1 is what the library itself generates for the fixnum 1.

You'd need to do: {"number" : 1} to be valid json. The bug is that

a != JSON.parse(JSON.generate(a))