Parsing JSON with muliline string values causes error #23

Closed
denyago opened this Issue Apr 3, 2012 · 1 comment

Comments

Projects
None yet
2 participants

denyago commented Apr 3, 2012

val = "a\r\nb"
j = JSONBuilder::Compiler.generate { v val }
# => "{\"v\": \"a\r\nb\"}"
JSON.parse j
# => JSON::ParserError: 756: unexpected token at '{"v": "a
# b"}'
#   from /home/di/.rvm/gems/ruby-1.9.2-p318@facewatch/gems/json_pure-1.6.6/lib/json/common.rb:148:in `parse'
#   from /home/di/.rvm/gems/ruby-1.9.2-p318@facewatch/gems/json_pure-1.6.6/lib/json/common.rb:148:in `parse'
#   from (irb):3
#   from /home/di/.rvm/gems/ruby-1.9.2-p318@facewatch/gems/railties-3.0.12/lib/rails/commands/console.rb:44:in `start'
#   from /home/di/.rvm/gems/ruby-1.9.2-p318@facewatch/gems/railties-3.0.12/lib/rails/commands/console.rb:8:in `start'
#   from /home/di/.rvm/gems/ruby-1.9.2-p318@facewatch/gems/railties-3.0.12/lib/rails/commands.rb:23:in `<top (required)>'
#   from script/rails:6:in `require'
#   from script/rails:6:in `<main>'
puts val
# a
# b
# => nil

Gems:

json (1.6.6, 1.6.5)
json_builder (3.1.0)
json_pure (1.6.6, 1.6.5)
multi_json (1.2.0, 1.1.0)

Workaround (I really don't like it!) for Rails:

j = JSONBuilder::Compiler.generate { v val.to_json.gsub('"','') }

dewski closed this in e5c3cf2 Apr 4, 2012

Owner

dewski commented Apr 4, 2012

Thanks for reporting this! I pushed up 3.1.2 with the fix.

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