3 ms·
> JSON schemas are modeled closely after XML schemas. Are you talking specifically about XSD and JSONSchema? If so I don't think this is really true. Pretty su
by theteapot 4y ago
> JSON schemas are modeled closely after XML schemas.
Are you talking specifically about XSD and JSONSchema? If so I don't think this is really true. Pretty sure the original authors of JSONSchema didn't pay much attention to XSD.
- magicalhippo 4y agoI don't know if they were looking at XSD, but I did write an XSD to JSON Schema[1] converter in an afternoon which does an almost perfect 1:1 mapping of a non-trivial XSD, including choice elements, basic restrictions etc. So for a lot of XSD's I'd say JSON Schema is effectively very close. Sadly, tooling for the latest JSON Schema (which is required for choice elements IIRC) is lacking, Swagger UI for example does not work well with it for example. [1]: https://json-schema.org/draft/2020-12/json-schema-core.html https://json-schema.org/draft/2020-12/json-schema-core.html
- theteapot 4y ago> I did write an XSD to JSON Schema[1] converter in an afternoon which does an almost perfect 1:1 mapping of a non-trivial XSD ... Can it do the reverse?
- magicalhippo 4y agoThat I haven't considered, given that at our work we had a bunch of XSD's and wanted to expand our integration point to accept JSON. I don't see any big issues with doing it in reverse for a subset of JSON Schema. What I haven't looked at is how large that subset would be. That is, if JSON Schema contains things that aren't possible to represent in XSD. For example, JSON Schema allows for some extensive conditional sub-schema logic. I used the "oneOf" to represent a XSD choice element, however JSON Schema also allows for such things as "if..then..else", which as a self-taught non-expert on XSD's I'm not sure how would map to XSD on a Saturday morning. Of course, there are things in XSD which can't be represented in JSON Schema either, I'm sure it's easy to come up with something that doesn't map. But from the typical XSD's I've seen and the ones we had in our company, the mapping could be done with just a single special-case. Given the lack of tooling around JSON Schema, my workflow now is to create/update the XSD and regenerate the JSON Schema.