{"action":"created","issue":{"url":"https://api.github.com/repos/JoshCheek/seeing_is_believing/issues/46","labels_url":"https://api.github.com/repos/JoshCheek/seeing_is_believing/issues/46/labels{/name}","comments_url":"https://api.github.com/repos/JoshCheek/seeing_is_believing/issues/46/comments","events_url":"https://api.github.com/repos/JoshCheek/seeing_is_believing/issues/46/events","html_url":"https://github.com/JoshCheek/seeing_is_believing/issues/46","id":42723996,"number":46,"title":"JSON.parse/encoding error","user":{"login":"JoshCheek","id":77495,"avatar_url":"https://avatars.githubusercontent.com/u/77495?v=3","gravatar_id":"","url":"https://api.github.com/users/JoshCheek","html_url":"https://github.com/JoshCheek","followers_url":"https://api.github.com/users/JoshCheek/followers","following_url":"https://api.github.com/users/JoshCheek/following{/other_user}","gists_url":"https://api.github.com/users/JoshCheek/gists{/gist_id}","starred_url":"https://api.github.com/users/JoshCheek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JoshCheek/subscriptions","organizations_url":"https://api.github.com/users/JoshCheek/orgs","repos_url":"https://api.github.com/users/JoshCheek/repos","events_url":"https://api.github.com/users/JoshCheek/events{/privacy}","received_events_url":"https://api.github.com/users/JoshCheek/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":9,"created_at":"2014-09-14T16:13:13Z","updated_at":"2015-03-22T00:33:21Z","closed_at":"2015-01-07T14:33:07Z","body":"### Versions:\r\n\r\n```\r\nSeeingIsBelieving::VERSION  \"2.1.4\"\r\nParser::VERSION             \"2.2.0.pre.4\"\r\nRUBY_VERSION                \"2.1.1\"\r\nENV['RUBY_VERSION']         \"2.1.1\"\r\n```\r\n\r\n### Input program\r\n\r\n```ruby\r\nrequire 'json'  # => false\r\n\r\ninitial = \"”\"  # => \"”\"\r\n\r\nresult =\r\n  JSON.dump(  # => JSON\r\n    initial   # => \"”\"\r\n  )           # => \"\\\"”\\\"\"\r\n\r\nJSON.parse result\r\n```\r\n\r\n\r\n### Wrapped program\r\n\r\n```ruby\r\nbegin; $SiB.number_of_captures = Float::INFINITY; $SiB.record_result(1, (require 'json'))\r\n\r\n$SiB.record_result(3, (initial = \"”\"))\r\n\r\n$SiB.record_result(8, (result =\r\n  $SiB.record_result(6, (JSON)).dump(\r\n    $SiB.record_result(7, (initial))\r\n  )))\r\n\r\n$SiB.record_result(10, (JSON.parse result));rescue Exception;lambda {line_number = $!.backtrace.grep(/#{__FILE__}/).first[/:\\d+/][1..-1].to_i;$SiB.record_exception line_number, $!;$SiB.exitstatus = 1;$SiB.exitstatus = $!.status if $!.kind_of? SystemExit;}.call;end\r\n```\r\n\r\n### Stdout from execution\r\n\r\nIs empty.\r\n\r\n### Stderr from execution\r\n\r\n```\r\n/Users/josh/.rubies/ruby-2.1.1/lib/ruby/2.1.0/json/common.rb:223:in `encode': \"\\xE2\" from ASCII-8BIT to UTF-8 (Encoding::UndefinedConversionError)\r\n\tfrom /Users/josh/.rubies/ruby-2.1.1/lib/ruby/2.1.0/json/common.rb:223:in `generate'\r\n\tfrom /Users/josh/.rubies/ruby-2.1.1/lib/ruby/2.1.0/json/common.rb:223:in `generate'\r\n\tfrom /Users/josh/.rubies/ruby-2.1.1/lib/ruby/2.1.0/json/common.rb:394:in `dump'\r\n\tfrom /Users/josh/.gem/ruby/2.1.1/gems/seeing_is_believing-2.1.4/lib/seeing_is_believing/the_matrix.rb:39:in `block in <top (required)>'\r\n```\r\n\r\n### Exit status\r\n\r\n1"},"comment":{"url":"https://api.github.com/repos/JoshCheek/seeing_is_believing/issues/comments/84482094","html_url":"https://github.com/JoshCheek/seeing_is_believing/issues/46#issuecomment-84482094","issue_url":"https://api.github.com/repos/JoshCheek/seeing_is_believing/issues/46","id":84482094,"user":{"login":"JoshCheek","id":77495,"avatar_url":"https://avatars.githubusercontent.com/u/77495?v=3","gravatar_id":"","url":"https://api.github.com/users/JoshCheek","html_url":"https://github.com/JoshCheek","followers_url":"https://api.github.com/users/JoshCheek/followers","following_url":"https://api.github.com/users/JoshCheek/following{/other_user}","gists_url":"https://api.github.com/users/JoshCheek/gists{/gist_id}","starred_url":"https://api.github.com/users/JoshCheek/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JoshCheek/subscriptions","organizations_url":"https://api.github.com/users/JoshCheek/orgs","repos_url":"https://api.github.com/users/JoshCheek/repos","events_url":"https://api.github.com/users/JoshCheek/events{/privacy}","received_events_url":"https://api.github.com/users/JoshCheek/received_events","type":"User","site_admin":false},"created_at":"2015-03-22T00:33:20Z","updated_at":"2015-03-22T00:33:20Z","body":"That's a different issue: it's blowing up because `\"√\"` is not valid as a toplevel JSON value.\r\n\r\nJSON only considers arrays and objects (ruby hashes) to be valid toplevel objects. [The spec](http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf) does a bad job of conveying this, but at the top of http://json.org/ it says:\r\n\r\n> JSON is built on two structures:\r\n> \r\n> * A collection of name/value pairs. In various languages, this is realized as an object,\r\n>   record, struct, dictionary, hash table, keyed list, or associative array.\r\n> * An ordered list of values. In most languages, this is realized as an array, vector, list, or sequence.\r\n\r\nYou can see it in Ruby's parsing code [here](https://github.com/ruby/ruby/blob/a77e89766bc753889d87242ea93a40a09b930d41/ext/json/parser/parser.rl#L736-739).\r\n\r\nThe default JSON parser can deal with this, it just doesn't by default, because that's apparently nonstandard. To get it to parse this, pass the key `quirks_mode` when you parse it.\r\n\r\n```sh\r\n$ ruby -rjson -e 'p JSON.parse(JSON.dump(\"√\"), quirks_mode: true)'\r\n\"√\"\r\n```"}}