Class: Grape::Validations::Types::JsonArray

Inherits:
Json
  • Object
show all
Defined in:
lib/grape/validations/types/json.rb

Overview

Specialization of the Json attribute that is guaranteed to return an array of objects. Accepts both JSON-encoded objects and arrays of objects, but wraps single objects in an Array.

Class Method Summary collapse

Class Method Details

.parse(input) ⇒ Array<Hash>

See Grape::Validations::Types::Json.parse. Wraps single objects in an array.

Parameters:

  • input (String)

    JSON-encoded parameter value

Returns:

  • (Array<Hash>)


60
61
62
63
# File 'lib/grape/validations/types/json.rb', line 60

def parse(input)
  json = super
  Array.wrap(json) unless json.nil?
end

.parsed?(value) ⇒ Boolean

See Grape::Validations::Types::Json.coerced_collection?

Returns:

  • (Boolean)


66
67
68
# File 'lib/grape/validations/types/json.rb', line 66

def parsed?(value)
  coerced_collection? value
end