# ActiveRecord to\_json encoding

**URL:** <https://discuss.rubyonrails.org/t/activerecord-to-json-encoding/45022>\
**Category:** rubyonrails-talk\
**Created:** [August 10, 2009, 10:32pm UTC](https://discuss.rubyonrails.org/t/activerecord-to-json-encoding/45022 "2009-08-10T22:32:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Frederick\_Cheung](https://sea2.discourse-cdn.com/rubyonrails/user_avatar/discuss.rubyonrails.org/frederick_cheung/32/3901_2.png) [@Frederick\_Cheung](https://discuss.rubyonrails.org/u/Frederick_Cheung)\
**Post date:** [August 10, 2009, 10:32pm UTC](https://discuss.rubyonrails.org/t/activerecord-to-json-encoding/45022/1 "2009-08-10T22:32:36Z")

</div>

> Question: Hi, our company is using Ruby 1.8.6 with Rails 2.2.2. Does anyone know how we can explicitly specify what encoding to use when calling .to\_json on an ActiveRecord?
> 
> Description: We have some multibyte characters in our database. For example we have a table with a name column that has this French accented e: Café Records. When we serialize this object using ActiveRecord's to\_xml() everything looks fine in the browser and with our json objects.
> 
> When we render JSON using to\_json() we are seeing problems where the accented 'e' character is getting mangled and causes our calling web client to fail since it's expecting properly UTF-8 encoded characters.

What's actually stored in the database ? If you open up a console and find the relevant object in the database what does the name attribute contain ? I don't think that to\_json does much more than spit out the data ActiveRecord already has.

Fred

---

<div class="post-metadata">

**Author:** ![Frederick\_Cheung](https://sea2.discourse-cdn.com/rubyonrails/user_avatar/discuss.rubyonrails.org/frederick_cheung/32/3901_2.png) [@Frederick\_Cheung](https://discuss.rubyonrails.org/u/Frederick_Cheung)\
**Post date:** [August 10, 2009, 11:25pm UTC](https://discuss.rubyonrails.org/t/activerecord-to-json-encoding/45022/2 "2009-08-10T23:25:32Z")

</div>

That's not what I meant. What are the actual bytes stored in the database ? What encoding does the database think this column is in. If, in a ruby console, you inspect the bytes contained in the name column what do you see ?

Fred
