Comment by abustamam

5 hours ago

Json has json schema. What are DTDs?

JSON Schema has existed for maybe 6 years in theory, in practice a few years.

As for DTD: https://en.wikipedia.org/wiki/Document_type_definition

Basically it tells the system what elements are allowed in which places and what attributes they can contain.

    <!ELEMENT html (head, body)>

Defines a html element that can contain a head and body, nothing else. Anything extra or missing will fail the validator.

It was kinda-sorta eventually superseded by XML Schema that could also define what KIND of data the attributes could contain, but did exist at the top of XML/HTML/SGML documents for years.

  • Ah interesting. Whenever I write an API I'll use Zod and whatever middlewares my framework needs to generate json schema for consumers, and whenever I consume an API I will use Zod to parse.

    It would be nice if it were just built into the spec though!