4

Say I have two json-schemas - is it possible (in python or anywhere else) to determine if one is a subset of another?

I am looking for a function on two json-schemas that will return true if and only if every instance accepted by the first json-schema is also accepted by the second.

For a super simple example, suppose my schemas are

int_schema = {'type': 'integer'}
num_schema = {'type': 'number'}

Then I would have

subset(int_schema, num_schema) = True
subset(num_schema, int_schema) = False

Don't really care about this being python, I am more trying to find out if json-schema supports this.

martineau
  • 119,623
  • 25
  • 170
  • 301

1 Answers1

0

So far, the only project I found that does what you want is this Javascript implementation.

A Python implementation (or even a comand line utility) would be so useful considering JSON Schemas really shine when back-end and front-end communicate, and JavaScript is not the most popular backend language, but is a very popular front-end one.

If anyone feel inspired out there, a pushdown automaton would be the perfect tool for that exact task !

Another approach would be to write a meta schema for the num_schema and try to validate the int_schema against it. Meta schema are self-descriptive and you can validate other schemas against them (hence meta).

Samuel Prevost
  • 1,047
  • 1
  • 11
  • 30