ohler55/oj — pull request #112 by dvdplm (2013-10-30 22:50:44+00:00)
Title: Add :escape_entities option to escape &, < and > into '\u0026', '\u003E' and '\u003C'

There is currently no option to escape of these chars in any JSON library I know of. This is the default behavior for Rails 4 (http://stackoverflow.com/questions/17936318/why-does-is-rails-4-unicode-escaping-in-to-json) and for some other languages, notably the Golang standard library. PHP also has an option to turn it on.

Is this something you would consider?

I am very unhappy with the implementation of the logic to decide whether to escape or not. The conditional on line 511 in this version is yucky. I think the proper way to do this is to introduce a new number in the char-type map hibit_friendly_chars/ascii_friendly_chars and use that in the switch stmt to see if it's a char we want to escape. Maybe even a new char-type map entirely?