Error: lexical error: invalid bytes in UTF8 string. When parsing the response.

Added line "json = json.encode('utf-8', 'binary', :invalid => :replace, :undef => :replace)" to fix the folowin error "Error: lexical error: invalid bytes in UTF8 string."