From: caleb clausen Date: 2009-09-30T02:53:08+09:00 Subject: [ruby-core:25853] [Bug #2160] JSON can't parse input where top-level object is a string Bug #2160: JSON can't parse input where top-level object is a string http://redmine.ruby-lang.org/issues/show/2160 Author: caleb clausen Status: Open, Priority: Normal Category: ext ruby -v: ruby 1.9.1p129 (2009-05-12 revision 23412) [i686-linux] JSON.parse blows up when passed an input whose top-level object is a string. For example: irb(main):009:0> JSON.parse '"foo"' JSON::ParserError: 574: unexpected token at '"foo"' from /usr/local/lib/ruby-1.9.1/lib/ruby/1.9.1/json/common.rb:122:in `parse' from /usr/local/lib/ruby-1.9.1/lib/ruby/1.9.1/json/common.rb:122:in `parse' from (irb):9 from /usr/local/bin/irb191:12:in `
' Note that '"foo"' is the output of JSON.unparse for the string "foo"; this object ought to round-trip through json properly. This problem does not happen when the string is contained in some other object, like an array: irb(main):010:0> JSON.parse '["foo"]' => ["foo"] This problem has also been observed in 1.9.2dev (and 1.8.6 with the json gem installed). ---------------------------------------- http://redmine.ruby-lang.org