XML is more descriptive and easier to read, JSON is smaller, so uses less bandwidth to pass around.
Which one is easier to read?
<animals>
<dog name="superdog">
<legs>4</legs>
<eyes>2</eyes>
</dog>
<cat name="catman">
<legs>4</legs>
<eyes>2</eyes>
</cat>
<pig name="superpig">
<legs>4</legs>
<eyes>2</eyes>
</pig>
<cow name="supercow">
<legs>4</legs>
<eyes>2</eyes>
</cow>
<mutant name="xman">
<legs>8</legs>
<eyes>16</eyes>
</mutant>
</animals>
VS
{
"animals": [{
"type": "dog",
"name": "superdog",
"properties": [{
"legs": 4
}, {
"eyes": 2
}]
}, {
"type": "cat",
"name": "catman",
"properties": [{
"legs": 4
}, {
"eyes": 2
}]
}, {
"type": "pig",
"name": "superpig",
"properties": [{
"legs": 4
}, {
"eyes": 2
}]
}, {
"type": "cow",
"name": "supercow",
"properties": [{
"legs": 4
}, {
"eyes": 2
}]
}, {
"type": "mutant",
"name": "xman",
"properties": [{
"legs": 8
}, {
"eyes": 16
}]
}]
}
I personally think the XML reads easier, especially when going many layers of nested properties deep, but I'd rather send JSON over the wire.
If small message size is what you're looking for, rather go for something binary like Message Pack and when you need to display it somewhere, display it in XML.
The Message Pack equivalent in HEX would be:
81 a7 61 6e 69 6d 61 6c 73 95 83 a4 74 79 70 65 a3 64 6f 67 a4 6e 61 6d 65 a8 73 75 70 65 72 64 6f 67 aa 70 72 6f 70 65 72 74 69 65 73 92 81 a4 6c 65 67 73 04 81 a4 65 79 65 73 02 83 a4 74 79 70 65 a3 63 61 74 a4 6e 61 6d 65 a6 63 61 74 6d 61 6e aa 70 72 6f 70 65 72 74 69 65 73 92 81 a4 6c 65 67 73 04 81 a4 65 79 65 73 02 83 a4 74 79 70 65 a3 70 69 67 a4 6e 61 6d 65 a8 73 75 70 65 72 70 69 67 aa 70 72 6f 70 65 72 74 69 65 73 92 81 a4 6c 65 67 73 04 81 a4 65 79 65 73 02 83 a4 74 79 70 65 a3 63 6f 77 a4 6e 61 6d 65 a8 73 75 70 65 72 63 6f 77 aa 70 72 6f 70 65 72 74 69 65 73 92 81 a4 6c 65 67 73 04 81 a4 65 79 65 73 02 83 a4 74 79 70 65 a6 6d 75 74 61 6e 74 a4 6e 61 6d 65 a4 78 6d 61 6e aa 70 72 6f 70 65 72 74 69 65 73 92 81 a4 6c 65 67 73 08 81 a4 65 79 65 73 10
Jan Vladimir Mostert
Idea Incubator