Created
July 26, 2013 00:27
-
-
Save apsoto/6085088 to your computer and use it in GitHub Desktop.
JSON sample validation
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
{ | |
"$schema" : "http://json-schema.org/draft-04/schema#", | |
"type" : "object", | |
"properties" : { | |
"class" : { | |
"type" : "array", | |
"items" : { | |
"type" : "integer" | |
} | |
} | |
} | |
} |
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
{ | |
"$schema" : "http://json-schema.org/draft-04/schema#", | |
"type" : "object", | |
"properties" : { | |
"class" : { | |
"allOf" : [{"$ref":"definitions.json#/definitions/sirenClass"}] | |
} | |
} | |
} |
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
{ | |
"$schema" : "http://json-schema.org/draft-04/schema#", | |
"type" : "object", | |
"definitions" : { | |
"sirenClass" : { | |
"type" : "array", | |
"items" : { | |
"type" : "integer" | |
} | |
} | |
} | |
} |
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
> schema | |
=> "bundle_with_ref.json" | |
> data | |
=> "{\"class\":[\"collection\"]}" | |
> JSON::Validator.clear_cache ; JSON::Validator.fully_validate(schema, data, validate_schema:true, record_errors:true) | |
=> [] | |
> schema='bundle_no_ref.json' | |
=> "bundle_no_ref.json" | |
> JSON::Validator.clear_cache ; JSON::Validator.fully_validate(schema, data, validate_schema:true, record_errors:true) | |
=> ["The property '#/class/0' of type String did not match the following type: integer in schema file:///Users/asoto/projects/wurl/servers/wurl-api/bundle_no_ref.json#"] |
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
{ | |
"class" : [ "collection" ] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment