3 ms·
I use jsonschema to validate my projects' output, and also generate the documentation from it. The python jsonschema support makes this possible: our testsuite
by RustyRussell 5y ago
I use jsonschema to validate my projects' output, and also generate the documentation from it. The python jsonschema support makes this possible: our testsuite is in Python already.
But it's an awkward fit, and I despair of having anyone else in my team write schemas: the default of allowing additional unspecified fields must be continually overridden, otherwise your schema has no teeth, and things like "if this field is this value, these additional fields exist" must then always have an "else" indicating that no additional fields exist.
In summary, it's better than nothing, but it's not easy. I'm not sure that JSON is a great language to specify schemas in, sorry.
- tored 5y agoYes, the unspecified fields is a nuisance. It is hard to manually look at JSON data and compare it visually to a JSON schema because the schema has a depth to every property and lots of other cruft, which makes it somewhat cumbersome to retrofit a JSON schema to existing JSON data. I once developed an alternative JSON schema internally for a company where the structure was the same as the JSON data (and default strict of course). We implemented multiple implementations for every language we used. It sort of worked, not as feature complete as the official JSON schema of course, but my conclusion is that JSON doesn't fit well for this.
- paulddraper 5y ago> otherwise your schema has no teeth I don't disagree, but FWIW, this is common deliberate choice. E.g. Protobufs work exactly the same way. Except unlike JSONSchema, there's no way to disable it. The reasoning is to permit future extensibility.
- RustyRussell 5y agoFor JSON itself, ignoring extra fields it makes sense. For validating my own output, it does not. And validating someone else's output seems counterproductive?