Encoding problem, YARD and JSON

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Encoding problem, YARD and JSON

trans
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?

Reply | Threaded
Open this post in threaded view
|

Re: Encoding problem, YARD and JSON

Robert Klemme-2
On Sun, Dec 18, 2011 at 6:23 PM, Intransition <[hidden email]> 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



--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

Reply | Threaded
Open this post in threaded view
|

Re: Encoding problem, YARD and JSON

trans
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.