# "Some String \\xAE".to\_json gives an illegal/malformed error?

**URL:** <https://www.ruby-forum.com/t/some-string-xae-to-json-gives-an-illegal-malformed-error/118231>\
**Category:** Ruby\
**Created:** [October 25, 2007, 12:16am UTC](https://www.ruby-forum.com/t/some-string-xae-to-json-gives-an-illegal-malformed-error/118231 "2007-10-25T00:16:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![blackie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/8491ac/32.png) [@blackie](https://www.ruby-forum.com/u/blackie)\
**Post date:** [October 25, 2007, 12:16am UTC](https://www.ruby-forum.com/t/some-string-xae-to-json-gives-an-illegal-malformed-error/118231/1 "2007-10-25T00:16:06Z")

</div>

Call me crazy, but I must be missing some fundamental understanding  
here.

> From what I can read on the JSON gem located here (http://  
> [json.rubyforge.org/](http://json.rubyforge.org/)) this should be working but I’m getting a  
> JSON::GeneratorError. Any insight you may have is appreciated.

Given this:

require ‘json’  
=\> true

s = [“MyStuff \xAE”]  
=\> [“MyStuff \256”]

s.to\_json  
JSON::GeneratorError: source sequence is illegal/malformed  
from (irb):16:in `to\_json’  
from (irb):16

Since that string has a unicode char in it, should it not be escape to  
\uXXXX when re convert to JSON?

Any help is appreciated.

---

<div class="post-metadata">

**Author:** ![blackie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/8491ac/32.png) [@blackie](https://www.ruby-forum.com/u/blackie)\
**Post date:** [October 25, 2007, 1:05am UTC](https://www.ruby-forum.com/t/some-string-xae-to-json-gives-an-illegal-malformed-error/118231/2 "2007-10-25T01:05:49Z")

</div>

Never mind. Encoding on the DB is defaulting to latin-1. What I  
thought was unicode strings weren’t. _Sigh_ 🙂
