Friday, February 7, 2014

Ban Unknown Properties!

In XML, it is common to define a schema, in part to help with validation. This means that you can take an instance document, which is meant to conform to that XML schema, and test whether it really does, using a validation engine. Such testsing can be very useful to catch otherwise hard-to-spot errors - like misspelling an attribute name or getting the order of elements wrong.
Information Validations by dopey
JSON didn't originally have a schema language. However, IETF are developing one. When the IPTC created the standard for News in JSON, we decided to define a schema for NINJS, so that you can check whether your JSON objects conform to the standard.
JSON Card -- Front by equanimity
Currently, in the NINJS schema, we have set "additionalProperties" to false. That's because we want to make it possible to validate a JSON document using that schema. If we didn't set additionalProperties=false, then any property name - whether it is a deliberate provider extension or an inadvertent typo - will pass validation.
Property Line by Whatknot
On the other hand, this means that a provider who wants to add their own properties in the NINJS schema has to create their own local copy. We've explained how to do that on the dev website ( But it isn't totally obvious that is what you're meant to do. And it is certainly different from other schema that the IPTC has developed using XML (such an NewsML-G2), which instead have extensibility built in from the start. However, with IETF JSON Schema v4 (the latest) that's the only choice we have (
Ban Symbol by uvw916a
In the v5 version of JSON Schema, they are introducing "ban unknown properties mode" Rather than being something that is built into the schema (like additionalProperties), "ban unknown properties" is a directive to the validation engine. The v5 JSON Schema is due to be finalized Real Soon Now. And at least one JSON Schema validator supports it already
NEAT by wannaoreo
This seems to be a much neater solution to the validation problem. And, frankly, without it, the JSON schema isn't nearly as powerful. So, I'd like to see IPTC adopt this for the NINJS schema. And, if you're working on a JSON schema, I recommend you look at it, too.

No comments:

Post a Comment