JSON validation against JSON schemas: Why is this obvious JSON data not failing validation -
this json file should fail validation not. tell me why.
plug below json data , schema web site, validate,
http://json-schema-validator.herokuapp.com , same results in mule validate json schema. not comply schema (i added fields, misspelled fields, date-time value not real date time) yet not fail it. can tell me why?
json schema:
{ "$schema": "http://json-schema.org/draft-04/schema#", "id": "http://hud.gov/ocio/xsd/esb/serviceauditingframework/2.0#", "definitions": { "serviceauditlogdata": { "type": "object", "title": "serviceauditlogdata", "required": [ "servicerequesttimestamp", "sourcesystem" ], "properties": { "auditid": { "type": "string" }, "servicerequesttimestamp": { "type": "string", "format": "date-time" }, "serviceprovider": { "type": "string" }, "serviceproviderversion": { "type": "string" }, "serviceprovidertimestamp": { "type": "string", "format": "date-time" }, "eventtype": { "type": "string" }, "eventdetail": { "type": "string" }, "hostname": { "type": "string" }, "sourcesystem": { "type": "string" }, "authenticationid": { "type": "string" }, "enduserid": { "type": "string" }, "inputdata": { "type": "string" } }, "propertiesorder": [ "auditid", "servicerequesttimestamp", "serviceprovider", "serviceproviderversion", "serviceprovidertimestamp", "eventtype", "eventdetail", "hostname", "sourcesystem", "authenticationid", "enduserid", "inputdata" ] } } } json data
{ "serviceauditlogdata": { "junk":"asdfasdf", "servicerequesttimestamp": "2004-09-29t12:58:31.470z", "serviceprovider": "flqs", "serviceproviderversion": "v1.0.1", "audit_id": "17f24136-2494-4bf8-9d3b-9baafaae0cc9", "serviceprovidertimestamp": "2012-11-04t21:44:57.997z", "eventtype": "query pool", "eventdetail": "default pool", "hostname": "esb-d-srv1.", "sourcesystem": "lrs", "authenticationid": "esblrsaccount", "enduserid": "h574857", "inputdata": "l234234234, l32453462345, l23452346" } }
it not fail because schema not enforce constraint. notice definitions not jsonschema keyword constraints validation. used place sub-schemas re-used in other parts of schema definition. thus, start with, should change definitions keyword properties.
another common misunderstanding jsonschema related properties keyword. let's take following example:
{ "type" : "object", "properties" : { "key1" : { "type" : "string" } } } you must read as: json must object, , in case contains key equal key1, value must string. according following 2 json objects valid:
{ "key2":12 } and:
{ "key1":"sdf" } finally, related date-time format, must check section 6 of rfc3339 sure have valid date-time. , in case, implementation of formats not compulsory in jsonschema validators.
Comments
Post a Comment