{"id":1877,"date":"2018-05-31T00:00:00","date_gmt":"2018-05-30T22:00:00","guid":{"rendered":"https:\/\/wwwneu.strehle.de\/tim\/weblog\/archives\/2018\/05\/31\/1636-2\/"},"modified":"2025-07-31T21:37:27","modified_gmt":"2025-07-31T19:37:27","slug":"1636-2","status":"publish","type":"post","link":"https:\/\/www.strehle.de\/tim\/weblog\/archives\/2018\/05\/31\/1636-2\/","title":{"rendered":"The \u201cX\u201d in JSON stands for Extensibility"},"content":{"rendered":"\n<p><em>While I do use JSON, I still think XML is superior for some important use cases (long-lived data that may be exchanged with other systems). So here\u2019s a quick \u201crant\u201d \u2013 prompted by <a href=\"https:\/\/twitter.com\/danbri\/status\/988072703675383809\">Dan Brickley\u2019s response<\/a> to Bob DuCharme\u2019s <a href=\"http:\/\/www.snee.com\/bobdc.blog\/2018\/04\/reification-is-a-red-herring.html\">Reification is a red herring<\/a> \u2013 aimed at those (younger?) folks \u201cdissing\u201d XML \ud83d\ude42<\/em><\/p>\n\n\n\n<p>Over time, requirements and technology inevitably change. <strong>Extensibility<\/strong> (the \u201cX\u201d in XML) is the property that helps us adapt and keep pace, letting us evolve technology from simple to advanced without having to throw away and reimplement existing functionality. Here\u2019s two reasons why XML is better at it than JSON:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">From one to many<\/h3>\n\n\n\n<p><strong>Cardinality<\/strong> (whether data has one or multiple values) is a common problem in data modeling: In a relational database, you need to change the schema (creating an additional table) to turn a single-valued into a multi-valued field. Programming languages distinguish between scalar values and arrays or collections.<\/p>\n\n\n\n<p>Not so in XML; I can move effortlessly (on the producer side, at least) from single\u2026<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;book&gt;\n  &lt;author&gt;Alice&lt;\/author&gt;\n&lt;\/book&gt;\n<\/code><\/pre>\n\n\n\n<p>\u2026 to multiple without changing the syntax:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;book&gt;\n  &lt;author&gt;Alice&lt;\/author&gt;\n  &lt;author&gt;Bob&lt;\/author&gt;\n&lt;\/book&gt;\n<\/code><\/pre>\n\n\n\n<p>In JSON, if you do it the normal way (not making everything an array) \u2013 a single-valued property\u2026<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{author:\"Alice\"}\n<\/code><\/pre>\n\n\n\n<p>\u2026 needs to be changed to an array to support multiple values:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{author:&#91;\"Alice\",\"Bob\"]}\n<\/code><\/pre>\n\n\n\n<p>You could argue that this is one of the things that make XML hard for consumers. But I appreciate that changing the cardinality after a while doesn\u2019t force you to modify your data format.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Another dimension<\/h3>\n\n\n\n<p><strong>Attributes<\/strong> \u2013 adding additional information about data \u2013 is for free in XML (at least one level deep, and if you\u2019re not in an attribute already) ; you can go from\u2026<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;author&gt;Alice&lt;\/author&gt;\n<\/code><\/pre>\n\n\n\n<p>\u2026 to additional info without changing the format:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;author url=\"http:\/\/example.com\/alice\"&gt;Alice&lt;\/author&gt;\n<\/code><\/pre>\n\n\n\n<p>JSON doesn\u2019t offer that additional dimension; a scalar value\u2026<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{author:\"Alice\"}\n<\/code><\/pre>\n\n\n\n<p>\u2026 doesn\u2019t support metadata and has to be changed to an object first to support \u201cattributes\u201d:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{author:{name:\"Alice\",url:\"http:\/\/example.com\/alice\"}}\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Extensibility FTW<\/h3>\n\n\n\n<p>An important feature XML and JSON share is being able to add new fields at will without affecting existing consumers (unless you shoot yourself in the foot with overly rigid schemas or writing very dumb clients). But there\u2019s more that makes XML extensible (e.g., mixed content or namespaces).<\/p>\n\n\n\n<p>So when you design your next data interchange format, consider going XML to future-proof your data. Let me know if you disagree \ud83d\ude42<\/p>\n\n\n\n<p><em>(P.S.: <a href=\"\/tim\/weblog\/archives\/2013\/02\/08\/1555\">Topic Maps<\/a> offer an extremely extensible data model\u2026)<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>While I do use JSON, I still think XML is superior for some important use cases (long-lived data that may be exchanged with other systems). So here\u2019s a quick \u201crant\u201d \u2013 prompted by Dan Brickley\u2019s response to Bob DuCharme\u2019s Reification is a red herring \u2013 aimed at those (younger?) folks \u201cdissing\u201d XML \ud83d\ude42 Over time, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","_share_on_mastodon":"0"},"categories":[1],"tags":[],"class_list":["post-1877","post","type-post","status-publish","format-standard","hentry","category-weblog"],"share_on_mastodon":{"url":"","error":""},"_links":{"self":[{"href":"https:\/\/www.strehle.de\/tim\/wp-json\/wp\/v2\/posts\/1877","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.strehle.de\/tim\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.strehle.de\/tim\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.strehle.de\/tim\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.strehle.de\/tim\/wp-json\/wp\/v2\/comments?post=1877"}],"version-history":[{"count":1,"href":"https:\/\/www.strehle.de\/tim\/wp-json\/wp\/v2\/posts\/1877\/revisions"}],"predecessor-version":[{"id":1894,"href":"https:\/\/www.strehle.de\/tim\/wp-json\/wp\/v2\/posts\/1877\/revisions\/1894"}],"wp:attachment":[{"href":"https:\/\/www.strehle.de\/tim\/wp-json\/wp\/v2\/media?parent=1877"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.strehle.de\/tim\/wp-json\/wp\/v2\/categories?post=1877"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.strehle.de\/tim\/wp-json\/wp\/v2\/tags?post=1877"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}