#1 - May 20, 2011, 8:37 a.m.
{
"realms":[
{
"type":"pvp",
"queue":false,
"status":true,
"population":"medium",
"name":"Dunemaul",
"slug":"dunemaul"
},
{
"type":"pve",
"queue":false,
"status":true,
"population":"medium",
"name":"Medivh",
"slug":"medivh"
}
]
}
The example above contains 302 characters, 340 bytes and 20 lines. Of which 92 characters are spaces (45 per realm entry), 19 characters are carriage returns and 19 characters are line feeds as illustrated below.
{[\r][\n]
.."realms":[[\r][\n]
....{[\r][\n]"
......"type":"pvp",[\r][\n]
......"queue":false,[\r][\n]
......"status":true,[\r][\n]"
......"population":"medium",[\r][\n]
......"name":"Dunemaul",[\r][\n]
......"slug":"dunemaul"[\r][\n]
....},[\r][\n]"
....{[\r][\n]"
......"type":"pve",[\r][\n]
......"queue":false,[\r][\n]
......"status":true,[\r][\n]
......"population":"low",[\r][\n]
......"name":"Medivh",[\r][\n]
......"slug":"medivh"[\r][\n]
....}[\r][\n]
..][\r][\n]
}
Once collapsed/condensed the same information is contained in 210 characters, 210 bytes and of course 1 line. That is a net gain of a little over 38% ((340-210)/340*100) compared to the original byte size. JSON suffers from the same dramatic inflation that all hierarchical based notations do; it gets exponentially worse the more nested the data is. With the upcoming API’s where data becomes more nested I can see that number going way up.
Al the disadvantages of the redundant overhead are quite apparent. The advantage is also quite apparent: a more human friendly readable form. That is why I would like to plead for an additional parameter on all API URL’s with a JSON payload with which the overhead can be toggled on or off. Something along the lines of a boolean ‘collapse’ which can be set to ‘true’ or ‘false’. I would also recommend to have the payload be collapsed by default.
*EDIT*: typo