Skip to content

Instantly share code, notes, and snippets.

@nepalez
Created October 25, 2014 16:58
Show Gist options
  • Save nepalez/ac7d592b77577e62f367 to your computer and use it in GitHub Desktop.
Save nepalez/ac7d592b77577e62f367 to your computer and use it in GitHub Desktop.
json-schema test
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