Module: Vldt::JSON
Overview
JSON validations
Instance Method Summary collapse
-
#json ⇒ Object
Validate, that an object is valid JSON.
-
#with_json(validation) ⇒ Object
Validate an object after parsing it as a JSON string.
Instance Method Details
#json ⇒ Object
Validate, that an object is valid JSON.
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/vldt/json.rb', line 7 def json Predicate.new(:json) do |o| begin ::JSON.parse(o) true rescue TypeError, ::JSON::ParserError false end end end |
#with_json(validation) ⇒ Object
Validate an object after parsing it as a JSON string.
20 21 22 23 24 |
# File 'lib/vldt/json.rb', line 20 def with_json (validation) Common.chain( json, With.new(-> json { ::JSON.parse(json) }, validation)) end |