3 ms·
Json has json schema. What are DTDs?
by abustamam 6mo ago
Json has json schema. What are DTDs?
- theshrike79 6mo agoJSON 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 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.
- abustamam 6mo agoAh 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!