On Thu, Dec 8, 2016 at 10:49 PM, Andy Jones <Andy.Jones@jameshall.co.uk> wrote:
This is all kinds of annoying. JSON will apparently encode a String but not
decode it? :
...
[11] pry(main)> JSON.parse "foo".to_json
JSON::ParserError: 784: unexpected token at '"foo"'
which is annoying. Can anyone tell me when quirks_mode was introduced? This is for a Gem, and while it literally has one (1) user -- me -- I like to be comforted by the fantasy that someone else other than me might find it useful one day; for all I know they will demand Ruby 1.9 support...
i see : )
you can chose bw generate and to_json, depending on use case.
.. snippet from the manual..
···
On Thu, Dec 8, 2016 at 11:31 PM, Andy Jones <Andy.Jones@jameshall.co.uk> wrote:
I'm aware that it's documented. I said it was *annoying*. Which is a different thing
#--------------------------------------
JSON.generate only allows objects or arrays to be converted to JSON
syntax. to_json, however, accepts many Ruby classes even though it acts
only as a method for serialization:
which is annoying. Can anyone tell me when quirks_mode was introduced? This is for a Gem, and while it literally has one (1) user -- me -- I like to be comforted by the fantasy that someone else other than me might find it useful one day; for all I know they will demand Ruby 1.9 support...
: )
playing devils adv here
fwiw, i am not a big fan of quirks mode
try
JSON.dump
JSON.dump "foo"
=> "\"foo\""
JSON.dump "foo".to_json
=> "\"\\\"foo\\\"\""
only the following four methods are good enough for me. but ymmv.
check my crude analogy. like i said, use case : )