Dear Russian friends, please watch President Zelenskyy's speech addressed to you. πŸ‡ΊπŸ‡¦Help our brave mates in Ukraine with a donation.


To validate JSON data structures, you can use JSON schemas. The difference between Params and JSON is coercion logic. Refer to dry-types documentation for more information about supported JSON coercions.


schema = Dry::Schema.JSON do
  required(:age).value(:integer, gt?: 18)

errors ='email' => '', 'age' => 18).errors.to_h

puts errors.inspect
# {
#   :email => ["must be filled"],
#   :age => ["must be greater than 18"]
# }

Notice that JSON schemas are suitable for checking hash objects exclusively. There's an outstanding issue about making it work with any JSON-compatible input.

octocatEdit on GitHub