Following is taken from http://us.battle.net/api/wow/realm/status?realm=Medivh&realm=Dunemaul
{
"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
The PHP trim will only remove the whitespace on either side of the string, which won't buy you much if the string has a lot of whitespace inside of it. Once we finalize the character and guild APIs, we'll probably take out the pretty indentation from the JSON output. |
|
It was a conscious decision to expose the realm, character and guild data as 'pretty printed' during this preview period. |
|
I don't have the power or ability to do that. |