Ruby on Rails JSON.parse "unexpected token" error

1.6k views Asked by At

I am trying to parse JSON data in my Rails 4 application with JSON.parse. I keep getting this error:

757: unexpected token at '<?xml version="1.0" encoding="UTF-8"?> <Error><Code>AccessDenied</Code><Message>Access Denied</Message><RequestId>BB0CDD4F68DBE9C0</RequestId><HostId>SwLqpcx7wpspbYzXONm1XGRG46dGHxnDroplppsxqtU4v/iVwEGOvpRWpBNR+LMPduTldva/5Nk=</HostId></Error>'

enter image description here

1

There are 1 answers

0
Jan Klimo On BEST ANSWER

Looks like error response is not returned as JSON. You could do something like:

def reviews
  JSON.parse(reviews_json)['Reviews']
rescue JSON::ParserError
  []
end