One indication of how based the JavaScript object is is that JSON became the defacto standard for data exchange despite Microsoft's efforts to push XML on us

@wallhackio @aescling tree based structures are for cowards both JSON and XML are bad for data

XML is better for markup

@Lady @aescling i know you have a brain that can make sense of dry specification but for me that is the single worst way for me to learn a data exchange format lmao

@Lady @aescling i found a video of an indian man explaining the concept with a terrible microphone so i think i'm good

@wallhackio @aescling JSON is best used for closed APIs with known parameters, where a tight binding exists between the three schemas (see <en.wikipedia.org/wiki/Three-sc>)

when these things diverge JSON becomes less and less desirable

@wallhackio @aescling there are thing which are very easy to do on s-expressions or in XML which are a pain in the ass to do with JSON and those things are basically all of the nature “convert this structure into that structure”

strong argument for just deserializing into a lisp, transforming, and serializing back, and that makes one wonder why you aren’t just using a lisp as your structure to begin with

@wallhackio @aescling well javascript doesn’t have any native concept of object type so in order to transform JS you have to first identify the type of every object and then call the methods associated with that type

“identify the type of object” can be trivial in the case where every object has a `type` property, but that’s still boilerplate you have to write and most real-world JSON is not this verbose

the end result of all this is that most code for processing JSON is incredibly bespoke

in XML on the other hand, the type of things is obvious (it's the node name), so you can just use a generic recursive descent mechanism with type-specific transforms, and you don’t have to write the first part because that’s XSLT

example JSON:

{ "type": "example"
, "items":
[ { "type": "item"
, "value": 1 }
, { "type": "item"
, "value": 2 } ] }

example XML:

<example>
<items>
<item value="1"/>
<item value="2"/>
</items>
</example>

desired result:

<p>Here are my items: {1}, {2}.</p>

XSLT conversion:

<x:template match="example">
<p>
<x:text>Here are my items: </x:text>
<x:for-each select="items/*"/>
<x:if test="position()!=1">
<x:text>, </x:text>
</x:if>
<x:apply-templates select="."/>
</x:for-each>
<x:text>.</x:text>
</p>
</x:template>
<x:template match="item">
<x:text>{</x:text>
<x:value-of select="@value"/>
<x:text>}</x:text>
</x:template>

conversion from JSON left as an exercise

suppose a new item type is added. with XML/XSLT, this just necessitates adding a single new template to handle it. how much does the code need to change to accommodate this with JSON?

Sign in to participate in the conversation
📟🐱 GlitchCat

A small, community‐oriented Mastodon‐compatible Fediverse (GlitchSoc) instance managed as a joint venture between the cat and KIBI families.