Aaron D. Gifford wrote:
> irb(main):002:0> JSON.parse(JSON.generate('\\'))
> JSON::ParserError: 598: unexpected token at '"\\"'

This is simply because JSON.parse only parses JSON *objects* and 
*arrays*, not strings or numbers.

>> JSON.parse('{"foo":"bar"}')
=> {"foo"=>"bar"}
>> JSON.parse('["foo","bar"]')
=> ["foo", "bar"]
>> JSON.parse('"bar"')
JSON::ParserError: 574: unexpected token at '"bar"'

I use the following workaround:

>> json = JSON.generate('\\')
=> "\"\\\\\""
>> JSON.parse("[" + json + "]").first
=> "\\"

HTH,

Brian.
-- 
Posted via http://www.ruby-forum.com/.