class ActiveSupport::JSON::Encoding::JSONGemEncoder
def jsonify(value)
to +object.as_json+, not any of this method's recursive +#as_json+
Note: the +options+ hash passed to +object.to_json+ is only passed
or having to remember to call #as_json recursively.
worry about what base types of objects they are allowed to return
This allows developers to implement #as_json without having to
fully JSON-ready object.
Recursively calls #as_json to the object to recursively build a
and +true+/+false+/+nil+.
primitives like Hash, Array, String, Symbol, Numeric,
Convert an object into a "JSON-ready" representation composed of
def jsonify(value) case value when String, Integer, Symbol, nil, true, false value when Numeric value.as_json when Hash result = {} value.each do |k, v| k = k.to_s unless Symbol === k || String === k result[k] = jsonify(v) end result when Array value.map { |v| jsonify(v) } else jsonify value.as_json end end