Encoding problem, YARD and JSON

I have a Hash object I am trying to convert to JSON using the json
gem.
Using #to_json I am getting this error:

in `encode': "\xC3" from ASCII-8BIT to UTF-8

(Encoding::UndefinedConversionError)

Most of the content of that hash is being extracted from the YARD api.

Can anyone offer any idea on what the problem might be and how to fix?

On Sun, Dec 18, 2011 at 6:23 PM, Intransition [email protected]
wrote:

I have a Hash object I am trying to convert to JSON using the json gem.
Using #to_json I am getting this error:

in `encode’: “\xC3” from ASCII-8BIT to UTF-8
(Encoding::UndefinedConversionError)

Most of the content of that hash is being extracted from the YARD api.

Can anyone offer any idea on what the problem might be and how to fix?

To me it sounds as if the particular String in question was obtained
binary from the source (yard api probably) and there is a value which
cannot be converted to UTF8 (maybe because it is > 0x7F). You could
try correct encodings when fetching or force a particular encoding
(e.g. one of the latin 8bit encodings) - if you know the encoding.

Kind regards

robert

I ended up using #force_encoding to UTF-8 (and duping to unfreeze) every
value. Guess I’ll report it as a YARD issue and see what they say.

Thanks.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs