method
encode
rails latest stable - Class:
ActiveSupport::JSON::Encoding
Method not available on this version
This method is only available on newer versions. The first available version (v8.1.1) is shown here.
encode(value)public
Encode the given object into a JSON string
# File activesupport/lib/active_support/json/encoding.rb, line 183
def encode(value)
value = value.as_json(@options) unless @options.empty?
json = CODER.dump(value)
return json unless @escape
json.force_encoding(::Encoding::BINARY)
if @options.fetch(:escape_html_entities, Encoding.escape_html_entities_in_json)
if Encoding.escape_js_separators_in_json
json.gsub!(FULL_ESCAPE_REGEX, ESCAPED_CHARS)
else
json.gsub!(HTML_ENTITIES_REGEX, ESCAPED_CHARS)
end
elsif Encoding.escape_js_separators_in_json
json.gsub!(JS_SEPARATORS_REGEX, ESCAPED_CHARS)
end
json.force_encoding(::Encoding::UTF_8)
end