method
json_escape
v2.1.0 -
Show latest stable
-
0 notes -
Class: ERB::Util
- 1.0.0
- 1.1.0
- 1.1.1
- 1.1.6
- 1.2.0
- 1.2.6
- 2.0.0
- 2.0.1
- 2.0.3
- 2.1.0 (0)
- 2.2.1 (0)
- 2.3.2 (0)
- 2.3.8 (0)
- 3.0.0 (0)
- 3.0.5 (38)
- 3.0.7 (0)
- 3.0.9 (-4)
- 3.1.0 (0)
- 3.2.1 (0)
- 3.2.3 (0)
- 3.2.8 (0)
- 3.2.13 (0)
- What's this?
json_escape(s)
public
A utility method for escaping HTML entities in JSON strings. This method is also aliased as j.
In your ERb templates, use this method to escape any HTML entities:
<%=j @person.to_json %>
Example:
puts json_escape("is a > 0 & a < 10?") # => is a \u003E 0 \u0026 a \u003C 10?


