class Grape::Validations::Types::Json
all returned objects.
validation system will apply nested validation rules to
or Array object respectively. In either case the Grape
and arrays of objects, and will coerce the input to a Hash
types given as JSON-encoded strings. It accepts both JSON objects
Handles coercion and type checking for parameters that are complex
def coerced_collection?(value)
-
(true, false)-
Parameters:
-
value(Object) -- result of {#parse}
def coerced_collection?(value) value.is_a?(::Array) && value.all?(::Hash) end
def parse(input)
-
(Hash, Array-, nil)
Parameters:
-
input(String) -- a JSON-encoded parameter value
def parse(input) return input if parsed?(input) # Allow nulls and blank strings return if input.nil? || input.match?(/^\s*$/) JSON.parse(input, symbolize_names: true) end
def parsed?(value)
-
(true, false)-
Parameters:
-
value(Object) -- result of {#parse}
def parsed?(value) value.is_a?(::Hash) || coerced_collection?(value) end