HeadlinesBriefing favicon HeadlinesBriefing.com

Binary Packing Shrinks JSON by 80%

Hacker News •
×

A developer built a binary schema language that shrinks JSON payloads by 80%. Starting with basic ASCII encoding where each character takes one byte, they realized numbers stored as strings waste space—'104' uses 3 bytes instead of 1. The solution uses a [TYPE][LENGTH][DATA] structure, with a continuation bit in the header allowing variable-length encoding.

Strings become [TYPE=1][LENGTH=11][DATA], while integers use [TYPE=0][DATA=123]. For values over 127, a varint encoding uses the MSB as a continuation flag, combining 7-bit segments in little-endian format. This approach efficiently handles both strings and integers while minimizing overhead through bit-level optimization techniques.