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.
I ran into a problem upgrading to the latest version of json_builder. A recent commit refactored String#json_escape, and removed escaping of tabs.
The result:
irb> val = "a\tb"
=> "a\tb"
irb> j = JSONBuilder::Compiler.generate { v val }
=> "{\"v\": \"a\tb\"}"
irb> JSON.parse j
JSON::ParserError: 757: unexpected token at '{"v": "a b"}'
from /Users/jrallison/.rbenv/versions/1.9.3-p194-perf/gemsets/customerio/gems/json_pure-1.7.4/lib/json/common.rb:155:in `parse'
from /Users/jrallison/.rbenv/versions/1.9.3-p194-perf/gemsets/customerio/gems/json_pure-1.7.4/lib/json/common.rb:155:in `parse'
from (irb):6
from /Users/jrallison/.rbenv/versions/1.9.3-p194-perf/gemsets/customerio/gems/railties-3.2.2/lib/rails/commands/console.rb:47:in `start'
from /Users/jrallison/.rbenv/versions/1.9.3-p194-perf/gemsets/customerio/gems/railties-3.2.2/lib/rails/commands/console.rb:8:in `start'
from /Users/jrallison/.rbenv/versions/1.9.3-p194-perf/gemsets/customerio/gems/railties-3.2.2/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
I ran into a problem upgrading to the latest version of json_builder. A recent commit refactored
String#json_escape
, and removed escaping of tabs.The result:
This pull request adds back tab escaping.