On 2021-09-25, Peter J. Holzer <hjp-pyt...@hjp.at> wrote: > On 2021-09-24 23:32:47 -0000, Jon Ribbens via Python-list wrote: >> JSON Schema provides a way to denote composite types. > > I probably wasn't clear what I meant. In XML, every element has a tag, > which is basically its type. So by looking at an XML file (without > reference to a schema) you can tell what each element is. And a > validator can say something like "expected a 'product' or 'service' > element here but found a 'person'". > > In JSON everything is just an object or a list. You may guess that an > object with a field "product_id" is a product, but is one with "name": > "Billy" a person or a piece of furniture? > > I'm not familiar with JSON schema (I know that it exists and I've read a > tutorial or two but I've never used it in a real project), but as far as > I know it doesn't change that. It describes the structure of a JSON > document but it doesn't add type information to that document. So a > validator can at best guess what the malformed thing it just found was > supposed to be.
JSON Schema absolutely does change that. You can create named types and specify where they may appear in the document. With a well-defined schema you do not need to make any guesses about what type something is. -- https://mail.python.org/mailman/listinfo/python-list