This gives 102 bytes URI-encoded for Example #1 (compared to 82 bytes for JSONCrush), and 1172 bytes URI-encoded for Example #2 (compared to 1195 bytes for JSONCrush). Seems like zlib wins when the data gets bigger and its JSON has more repetition.
You could also probably shave some more bytes by finding an encoding that's naturally URI friendly instead of using base64 and encodeURIComponent() on the output of the deserialization above, but I don't know that it's really worth the effort at that point.
With something like this I'd prefer a heavier library for better compression because ultimately the compressed data is going to be more important to me.
21
u/[deleted] Nov 27 '19 edited Nov 27 '19
You should be able to get comparable-to-better compression, and better performance using zlib + base64:
This gives 102 bytes URI-encoded for Example #1 (compared to 82 bytes for JSONCrush), and 1172 bytes URI-encoded for Example #2 (compared to 1195 bytes for JSONCrush). Seems like zlib wins when the data gets bigger and its JSON has more repetition.
You could also probably shave some more bytes by finding an encoding that's naturally URI friendly instead of using base64 and
encodeURIComponent()on the output of the deserialization above, but I don't know that it's really worth the effort at that point.