-
-
Save nepalez/ac7d592b77577e62f367 to your computer and use it in GitHub Desktop.
json-schema test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'json-schema' | |
text = '{"uuid":"3ea8fd89-232f-4ed1-90b5-743da173cd7d","name":"FIRM"}' | |
schema = ' | |
{ | |
"$schema": "http://json-schema.org/draft-04/schema#", | |
"type": "object", | |
"properties": { | |
"uuid": { | |
"type": "string", | |
"format": "^[a-f\\d]{8}-([a-f\\d]{4}-){3}[a-f\\d]{12}$" | |
}, | |
"name": { "type": "string", "minLength": 1 }, | |
"num": { "type": "string", "minLength": 1 } | |
}, | |
"additionalProperties": false, | |
"required": ["uuid", "name"] | |
}' | |
JSON::Validator.validate!(schema, text, strict: true) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment