by mikepurvis · 1y ago · 0 comments
<?xml version="1.0"?>
<methodCall>
<methodName>math.add</methodName>
<params>
<param>
<value><int>5</int></value>
</param>
<param>
<value><int>7</int></value>
</param>
</params>
</methodCall>
Compared to this, JSON had string and number types built in: {
"jsonrpc": "2.0",
"method": "math.add",
"params": [5, 7],
"id": 1
}
I don't think this is the only factor, but I think XML had a lot of this kind of cognitive overhead built in, and that gave it a lot of friction when stacked up against JSON and later yaml... and when it came to communicating with a SPA, it was hard to compete with JS being able to natively eval the payload responses.In practice, it doesn't matter.
If the JSON payload is in the wrong format the server rejects it with an error.
If the server sends an integer "by mistake" then the purists would argue that the client should come to a halt and throw up an error to the user. Meanwhile the JSON users would see an integer coming back for the id field and use it, delivering something that works with the server as it exists today. Like it or not, this is why JSON wins.
Schema defined protocols are very useful in some circumstances, but in my experience the added overhead of keeping them in sync everywhere and across developers is a lot of overhead for most simple tasks.
Putting the data into a simple JSON payload and sending it off gets the job done in most cases.
It’s a mediocre data storage language.