Sha256: c8dfad7a3237ffa759a7bc622ca1ea459b455745d13c168b9231845f55b043c2
Contents?: true
Size: 963 Bytes
Versions: 6
Compression:
Stored size: 963 Bytes
Contents
require 'grape/validations' module Grape::Validators class Json < Grape::Validations::Base def validate_param!(field, params) begin JSON.parse( params[field] ) rescue fail Grape::Exceptions::Validation, params: [@scope.full_name(field)], message: 'must be valid JSON!' end end end class JsonArray < Grape::Validations::Base def validate_param!(field, params) begin raise unless JSON.parse( params[field] ).kind_of? Array rescue fail Grape::Exceptions::Validation, params: [@scope.full_name(field)], message: 'must be a valid JSON array!' end end end class JsonHash < Grape::Validations::Base def validate_param!(field, params) begin raise unless JSON.parse( params[field] ).kind_of? Hash rescue fail Grape::Exceptions::Validation, params: [@scope.full_name(field)], message: 'must be a valid JSON hash!' end end end end
Version data entries
6 entries across 6 versions & 1 rubygems