Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Bad behavior dumping hash with integer key #72

louman opened this Issue Feb 22, 2013 · 2 comments


None yet
2 participants

louman commented Feb 22, 2013

oj version: 2.0.7

~ ruby-1.9.3-p194 $ irb
1.9.3-p194 :001 > require 'oj'
Oj.dump => true

1.9.3-p194 :002 > Oj.dump({1 => 1})
=> "{"^#1":[1,1]}"

1.9.3-p194 :003 > Oj.dump({"1" => 1})
=> "{"1":1}"


ohler55 commented Feb 22, 2013

That is expected behavior. Oj default to :object mode which generates JSON that can be read in to reconstitute the Ruby Object that was dumped. Since the JSON spec requires keys to be strings the Hash key, 1 in the example must be encoded as a string. Try loading the generated JSON and note that is is the same as the dumped value.

Read the documentation on the other modes and try them out. One may be what you are looking for.


ohler55 commented Mar 1, 2013

No response, closing the issue.

@ohler55 ohler55 closed this Mar 1, 2013

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