Here’s the json string example
json = "{:status=>"ok", :hitcount=>"1", :request_date=>Wed, 10 Oct 2019 00:00:00 +0000}"
I have tried below mentioned snippet but this didn’t work and gives error JSON::ParserError (765: unexpected token at
require 'json'
JSON.parse(json)
3
Answers
Follow this JSON syntax for starters: https://restfulapi.net/json-syntax/
I believe your quotation marks inside your JSON are also causing an issue, you may have to escape them.
Unfortunately, JSON can’t represent Ruby symbols. JSON also requires both keys and values to be quoted, so what you’ve provided isn’t valid JSON and will break a JSON parser. You want just:
And then the Ruby JSON parser (thanks @engineersmnky!) has a nifty feature:
It does look like a formatting issue. For example if you were to have an ordinary hash with the same data, and convert it to JSON it will look a bit different:
You can see what I mean here: https://onlinegdb.com/tr6JVAV6y
So I’d guess you’ll need to see where that JSON is coming from and have it sent in a proper format.