@aescling did you like it
@aescling have you seen sleeping beauty
@aescling @wallhackio “shake it out” is a florence + the machine song which is better
@Satsuma lady
@aescling disney girl era?
@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?
@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 nice
@wallhackio @aescling JSON is best used for closed APIs with known parameters, where a tight binding exists between the three schemas (see <https://en.wikipedia.org/wiki/Three-schema_approach>)
when these things diverge JSON becomes less and less desirable
@wallhackio @aescling tree based structures are for cowards both JSON and XML are bad for data
XML is better for markup
@wallhackio @aescling JSDOM is extremely heavyweight and you’re unlikely to find a reasonably featureful replacement
if you don’t need the full DOM and just need simple parsing or whatever, there are probably options
@coriander i’m like “spiderman doesn’t believe in cops he’s just a teenager”
@aescling @wallhackio how come you never talk to them then
@aschmitz so like i could teach someone how to write good ruby code, which is a nice thing to learn and helpful to folks, but it’s not where my true power lies
Administrator / Public Relations for GlitchCat. Not actually glitchy, nor a cat. I wrote the rules for this instance.
“Constitutionally incapable of not going hard” — @aescling
“Fedi Cassandra” – @Satsuma
I HAVE EXPERIENCE IN THINGS. YOU CAN JUST @ ME.
I work for a library but I post about Zelda fanfiction.