JSON output replacing & with "\u0026 "

172 views
Skip to first unread message

Mario Gr

unread,
Oct 10, 2010, 10:42:17 AM10/10/10
to rubyonra...@googlegroups.com
Hi,

I'm outputting some database objects as static JSON files using a stand
along ruby script.rb, that other could run outside of my rails app. When
I use this script, the output replaces "&" with "\u0026." If I use the
same code to output my JSON files in console, it outputs fine.

I imagine there is some gem or something I'm not including in my
script.rb that would resolve this. Thoughts?

Thanks!
--
Posted via http://www.ruby-forum.com/.

Frederick Cheung

unread,
Oct 10, 2010, 11:39:21 AM10/10/10
to Ruby on Rails: Talk


On Oct 10, 3:42 pm, Mario Gr <li...@ruby-forum.com> wrote:
> Hi,
>
> I'm outputting some database objects as static JSON files using a stand
> along ruby script.rb, that other could run outside of my rails app. When
> I use this script, the output replaces "&" with "\u0026."  If I use the
> same code to output my JSON files in console, it outputs fine.
>
> I imagine there is some gem or something I'm not including in my
> script.rb that would resolve this.  Thoughts?

If you're using ActiveSupport's json stuff then
ActiveSupport::JSON::Encoding.escape_html_entities_in_json controls
this (although
\u0026 is perfectly u legal way of representing &)

Fred
>
> Thanks!
> --
> Posted viahttp://www.ruby-forum.com/.
Reply all
Reply to author
Forward
0 new messages