module ActiveSupport::JSON
def encode(value, options = nil)
ActiveSupport::JSON.encode({ key: "<>&" }, escape_html_entities: false)
global escape_html_entities_in_json configuration option.
This can be changed with the +escape_html_entities+ option, or the
# => "{\"key\":\"\\u003c\\u003e\\u0026\"}"
ActiveSupport::JSON.encode({ key: "<>&" })
it escapes <, >, and &:
By default, it also generates JSON that is safe to include in HTML, as
# => "{\"key\":\"\\u2028\"}"
ActiveSupport::JSON.encode({ key: "\u2028" })
U+2028 (Line Separator) and U+2029 (Paragraph Separator):
Generates JSON that is safe to include in JavaScript as it escapes
# => "{\"team\":\"rails\",\"players\":\"36\"}"
ActiveSupport::JSON.encode({ team: 'rails', players: '36' })
See http://www.json.org for more info.
Dumps objects in JSON (JavaScript Object Notation).
def encode(value, options = nil) Encoding.json_encoder.new(options).encode(value) end