[RFC] collapsable white space characters

#1 - May 20, 2011, 8:37 a.m.
Blizzard Post
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
Forum Avatar
Web & Mobile Team
#7 - May 20, 2011, 4:14 p.m.
Blizzard Post
05/20/2011 08:40 AMPosted by Ulminia
in php using the trim fuction will remove the whitespace but only on our side not blizzards. i hope they solve this otherwise there will be a larger then nessary increase in lag and bandwidth on the api's. and potental timeout on scripts running pull commands


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.
Forum Avatar
Web & Mobile Team
#14 - May 23, 2011, 4:24 a.m.
Blizzard Post
05/22/2011 03:19 PMPosted by Seafu
It seems really odd that they would return JSON with white space formatting in the first place. Not sure what implementation their using but I would of thought that their specifically adding the formating, which is more overhead plus bandwidth. Whitespace formatting on JSON is pointless when you have a tool like firebug


It was a conscious decision to expose the realm, character and guild data as 'pretty printed' during this preview period.
Forum Avatar
Web & Mobile Team
#16 - May 26, 2011, 3:36 p.m.
Blizzard Post
05/25/2011 08:31 PMPosted by Oxoxoxoxen
I think someone **COUGH*COUGH*Straton*COUGH** should comp Blabbermouth some game time for his efforts he put in to post on the US forms... :D


I don't have the power or ability to do that.