From: Brian Candler Date: 2010-03-08T21:39:52+09:00 Subject: Re: Ruby 1.9.1 built-in JSON troubles 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/.