Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shorten property names in JSON: does it make sense?

Concerning modern web applications and browsers. When sending from server to client (and vice versa) large objects (1-10MB raw text JSON size), does it make sense to shorten property name from:

people: {
  name: 'Alex'
  age: '999'
}

for example to:

p: {
  n: 'Alex'
  a: '999'
}

if we have huge number of such objects in the data?

Thus we can significantly reduce raw data size (up to 2-3 times). But does it make sense if GZip is used?

like image 240
WHITECOLOR Avatar asked Oct 02 '22 03:10

WHITECOLOR


1 Answers

It makes some sense, depending on your circumstances.

Obviously, if the value is quite large, there's not much point in shortening the key, but if you have very large JSON objects with relatively small values then shorter keys can save both storage on your system and transmission time.

But you do, of course, need to beware of "obfuscating" the JSON unnecessarily, leading to coding errors. In particular, it's probably best to use meaningful keys during development, then shorten them, if deemed necessary, prior to "ship".

In addition, if gzip (or similar) compression is used the shorter keys will make almost no difference in the size of the compressed object.

like image 65
Hot Licks Avatar answered Oct 11 '22 13:10

Hot Licks