Json Binary Format for Services

Matteo Bertozzi
November 21, 2026
15

Json Binary Format for Services

Matteo Bertozzi

November 21, 2026

Annual Pro sale · Save $30

Have presentations of your own?

Share with private links, password protection, and more control over your work.

Transcript

25 slides
  1. 1 44 43 6f 6c 61 04 00 00 c0

    3f c0 e2 c1 44 63 6f 6c 64 03 cc 01 45 57 61 74 65 72 04 00 00 40 3f Json Binary c0 e2 c1 44 63 6f 6c 64 03 cc 01 45 57 61 74 65 72 04 00 00 40 3f c0 e1 c1 03 ce 01 45 43 68 69 7 01 45 57 61 74 65 72 04 00 00 40 3f c0 e1 c1 03 ce 01 45 43 68 69 70 73 04 00 00 10 40 c0 e1 45 7 0 3f c0 e1 c1 03 ce 01 45 43 68 69 70 73 04 00 00 10 40 c0 e1 45 73 6e 61 63 6b 05 02 01 02 69 64 e2 c1 44 63 6f 6c 64 03 cc 01 45 57 61 74 65 72 04 00 00 40 3f c0 e1 c1 03 ce 01 45 43 68 69 70 7 f c0 e2 c1 44 63 6f 6c 64 03 cc 01 45 57 61 74 65 72 04 00 00 40 3f c0 e1 c1 03 ce 01 45 43 68 69 01 45 57 61 74 65 72 04 00 00 40 3f c0 e1 c1 03 ce 01 45 43 68 69 70 73 04 00 00 10 40 c0 e1 45 0 3f c0 e1 c1 03 ce 01 45 43 68 69 70 73 04 00 00 10 40 c0 e1 45 73 6e 61 63 6b 05 02 01 02 69 64 0 e2 c1 44 63 6f 6c 64 03 cc 01 45 57 61 74 65 72 04 00 00 40 3f c0 e1 c1 03 ce 01 45 43 68 69 70 JSON 3f c0 e2 c1 44 63 6f 6c 64 03 cc 01 45 57 61 74 65 72 04 00 00 40 3f c0 e1 c1 03 ce 01 45 43 68 69 {} 01 45 57 61 74 65 72 04 00 00 40 3f c0 e1 c1 03 ce 01 45 43 68 69 70 73 04 00 00 10 40 c0 e1 45 40 3f c0 e1 c1 03 ce 01 45 43 68 69 70 73 04 00 00 10 40 c0 e1 45 73 6e 61 63 6b 05 02 01 02 69 c0 e2 c1 44 63 6f 6c 64 03 cc 01 45 57 61 74 65 72 04 00 00 40 3f c0 e1 c1 03 ce 01 45 43 68 69 7 1 45 57 61 74 65 72 04 00 00 40 3f c0 e1 c1 03 ce 01 45 43 68 69 70 73 04 00 00 10 40 c0 e1 45 73 binary cc 01 45 57 61 74 65 72 04 00 00 40 3f c0 e1 c1 03 ce 01 45 43 68 69 70 73 04 00 00 10 40 c0 e1 4 0 40 3f c0 e1 c1 03 ce 01 45 43 68 69 70 73 04 00 00 10 40 c0 e1 45 73 6e 61 63 6b 05 02 01 02 69 c0 e2 c1 44 63 6f 6c 64 03 cc 01 45 57 61 74 65 72 04 00 00 40 3f c0 e1 c1 03 ce 01 45 43 68 69 7 01 45 57 61 74 65 72 04 00 00 40 3f c0 e1 c1 03 ce 01 45 43 68 69 70 73 04 00 00 10 40 c0 e1 45 7 Data Format cc 01 45 57 61 74 65 72 04 00 00 40 3f c0 e1 c1 03 ce 01 45 43 68 69 70 73 04 00 00 10 40 c0 e1 0 40 3f c0 e1 c1 03 ce 01 45 43 68 69 70 73 04 00 00 10 40 c0 e1 45 73 6e 61 63 6b 05 02 01 02 69 f c0 e2 c1 44 63 6f 6c 64 03 cc 01 45 57 61 74 65 72 04 00 00 40 3f c0 e1 c1 03 ce 01 45 43 68 69 for APIs format design · wire specs · benchmarks
  2. {} Client Why JSON Binary Format Design magic payload crc

    Wire Specs Encoding Rules API Service Benchmarks ...And Trade-Offs JSON binary
  3. {} JSON binary Why JSON Binary The Cost of Text

    on API Pages { "rows": [ { "id": 101, "name": "Cola", "price": 1.5, "currency": "EUR" }, { "id": 102, "name": "Water", "price": 0.75, "currency": "EUR" }, { "id": 103, "name": "Chips", "price": 2.25, "currency": "EUR" }, ... 5,000 rows per page ], "image": "iVBORw0KGgoAAAANSUhEUg..." Every row repeats every key Repeated values are written again and again Numbers are decimal text: scanned, then parsed } Binary data needs base64: +33% bytes
  4. {} JSON binary Format Design Goals and Non-Goals Goals JSON

    +bytes keys strings Non-Goals Same data model: null, bool, number, string, array, object stream No streaming / indefinite-length containers Native raw bytes, never base64 schema No external schema registry Each field name written once per message canon No canonical key ordering Repeated string values deduplicated when it pays off types No built-in date, decimal or custom types order Original object field order preserved simple A few tables plus a small recursive value decoder A full-buffer format for already materialized HTTP request and response bodies
  5. {} JSON binary Wire Specs Message Layout 4 bytes ASCII

    1 byte uvarint tables + root value optional · 4 bytes LE magic flags payload length payload checksum bit 0x01 = CRC32C footer present other bits reserved, must be zero CRC32C over every previous byte: magic, flags, length, payload Decoder checks the declared length against the buffer before reading data
  6. {} JSON binary payload := fieldCount stringCount shapeCount fieldTable stringTable

    shapeTable rootValue Wire Specs Payload Layout :uvarint :uvarint :uvarint fieldCount × (len:uvarint, utf8) stringCount × (len:uvarint, utf8) shapeCount × (n:uvarint, fieldIndex × n) tagged value tree The encoder pre-scans the whole value tree, then writes the dictionaries first
  7. {} JSON binary Wire Specs Per-Message Dictionaries Field Table String

    Table Shape Table — Every distinct object key, once — Only repeated values (≥ 2 uses) — An ordered list of field indexes — Ordered by frequency: hot keys get 1byte indexes — Kept only if table + refs < inline copies — ≥ 2 fields, ≥ 2 uses, must save bytes — Ordered by estimated savings — Same keys in a different order = different shape — Ties broken by first-seen order — Objects never carry inline key bytes — Index 0..31 is a single-byte ref fieldIndex / shapeIndex codec 0x00..0xfe direct index 0..254 0xff escape + uvarint(index − 255) — Shaped rows carry values only
  8. {} 0x00 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08

    0x09 0x0a 0x0b 0x0c 0x0d 0x0e 0x0f JSON binary Value Tags null false true integer float32 float64 string ref string bytes array object shaped object shaped obj array packed int array packed float32 packed float64 Fixed Tags 0x00 – 0x0F + zigzag varint + 4 bytes LE + 8 bytes LE + stringIndex:uvarint + len:uvarint + utf8 + len:uvarint + raw bytes + count:uvarint + value* + count:uvarint + (fieldIndex, value)* + shapeIndex + value* + shapeIndex + count:uvarint + value* + count:uvarint + varint* + count:uvarint + raw float32 + count:uvarint + raw float64 Shapes and packed arrays remove per-item overhead
  9. JSON {} binary 0x00 Value Tags Inline Tag Families 0x40

    0x80 0xc0 0x00–0x0f fixed tags 0x10–0x3f inline integer −16..31 0x40–0x7f short string, 0..63 bytes 0x80–0xbf short bytes, 0..63 bytes 0xc0–0xdf string ref #0..31 0xe0–0xef array, 0..15 items 0xf0–0xff object, 0..15 fields The tag byte alone carries small values and container counts: one byte for most numbers, keys and short lists 0xff
  10. {} JSON binary Encoding Rules // integers: one wire family,

    any size −16..31 0x10 + (v + 16) 1 byte other 0x03 + zigzag varint 0→0 −1→1 Scalars 1→2 −2→3 // floats: smallest exact form 0x04 float32 if the value round-trips exactly 0x05 float64 otherwise · NaN / ±Inf rejected // strings and bytes, length in bytes 0x40..0x7f short string 0x07 long string 0x80..0xbf short bytes 0x08 long bytes 0xc0..0xdf string ref 0..31 0x06 string ref + uvarint [1, 200, -3, 70000] 0d 04 02 90 03 05 e0 c5 08 packed int array · 4 items
  11. {} JSON binary Encoding Rules Arrays and Objects // array:

    first rule that matches 0x0c all items objects, same selected shape 0x0d all ints, packed varints smaller 0x0e all doubles exact as float32 0x0f all doubles 0xe0+n 0..15 items 0x09 count:uvarint + items // object 0x0b key list matches a selected shape → values only 0xf0+n 0..15 fields 0x0a count:uvarint → (fieldIndex, value) pairs Missing fields are not implicit nulls: objects are shaped by their exact, ordered key list
  12. {} JSON binary Shapes Exact, Ordered Key Lists // same

    keys, same order → one shape [ {"a": 10, "b": 20}, {"a": 20, "b": 30} ] // different key → two inline objects [ {"a": 10, "b": 20}, {"a": 30, "c": 40} ] fields 0="a" 1="b" shape 0 [0, 1] 0c 00 02 2a 34 34 3e fields 0="a" 1="b" 2="c" shapes none e2 f2 00 2a 01 34 f2 00 3e 02 03 50 0c shaped object array · shape 0 · 2 rows, then values only: 10 20 20 30 as 1 byte each
  13. {} JSON binary Worked Example Three API Rows, Byte by

    Byte [ { "id": 101, "name": "Cola", "price": 1.5, "currency": "EUR", "tags": ["drink", "cold"] }, { "id": 102, "name": "Water", "price": 0.75, "currency": "EUR", "tags": ["drink"] }, { "id": 103, "name": "Chips", "price": 2.25, "currency": "EUR", "tags": ["snack"] } ] [magic] 00 6e flags · payload length 110 05 02 01 5 fields · 2 strings · 1 shape 02 id 04 name 05 price 08 currency 04 tags field table 03 EUR 05 drink string table 05 00 01 02 03 04 shape 0 = all five fields 0c 00 03 shaped array · shape 0 · 3 rows 03 ca 01 44 Cola 04 00 00 c0 3f c0 e2 c1 44 cold 03 cc 01 45 Water 04 00 00 40 3f c0 e1 c1 03 ce 01 45 Chips 04 00 00 10 40 c0 e1 45 snack Keys and the repeated values "EUR" and "drink" are written once
  14. {} JSON binary Worked Example Three API Rows, Byte by

    Byte [ { "id": 101, "name": "Cola", "price": 1.5, "currency": "EUR", "tags": ["drink", "cold"] }, { "id": 102, "name": "Water", "price": 0.75, "currency": "EUR", "tags": ["drink"] }, { "id": 103, "name": "Chips", "price": 2.25, "currency": "EUR", "tags": ["snack"] } ] [magic] 00 6e flags · payload length 110 05 02 01 5 fields · 2 strings · 1 shape 02 id 04 name 05 price 08 currency 04 tags field table 03 EUR 05 drink string table 05 00 01 02 03 04 shape 0 = all five fields 0c 00 03 shaped array · shape 0 · 3 rows 03 ca 01 44 Cola 04 00 00 c0 3f c0 e2 c1 44 cold 03 cc 01 45 Water 04 00 00 40 3f c0 e1 c1 03 ce 01 45 Chips 04 00 00 10 40 c0 e1 45 snack One shape describes every row: rows carry values only
  15. {} JSON binary Worked Example Three API Rows, Byte by

    Byte [ { "id": 101, "name": "Cola", "price": 1.5, "currency": "EUR", "tags": ["drink", "cold"] }, { "id": 102, "name": "Water", "price": 0.75, "currency": "EUR", "tags": ["drink"] }, { "id": 103, "name": "Chips", "price": 2.25, "currency": "EUR", "tags": ["snack"] } ] [magic] 00 6e flags · payload length 110 05 02 01 5 fields · 2 strings · 1 shape 02 id 04 name 05 price 08 currency 04 tags field table 03 EUR 05 drink string table 05 00 01 02 03 04 shape 0 = all five fields 0c 00 03 shaped array · shape 0 · 3 rows 03 ca 01 44 Cola 04 00 00 c0 3f c0 e2 c1 44 cold 03 cc 01 45 Water 04 00 00 40 3f c0 e1 c1 03 ce 01 45 Chips 04 00 00 10 40 c0 e1 45 snack 03 ca 01 44 04 .. c0 e2 c1 int 101 (zigzag 202) JSON 225 B short string, 4 bytes CBOR 158 B float32 1.5 JSON Binary 116 B string ref #0 → "EUR" +4 B with CRC array of 2 · ref #1 → "drink"
  16. {} JSON binary Integrity Decoder Validation Order 1 verify magic

    2 verify flags are supported 3 read payload length 4 check message length (± checksum) 5 verify CRC32C before decoding user data 6 read field table 7 read string table 8 read shape table 9 decode the root value 10 reject trailing bytes per-frame decode limits (defaults) MaxPayloadBytes 128 MiB MaxDecodedBytes 512 MiB MaxValues 16,777,216 MaxDepth 256 MaxIntegerBytes 4,096 Counts, lengths, references and container sizes are checked before any allocation, even for checksum-valid frames
  17. {} JSON binary Benchmarks Methodology // setup host threads input

    JSON CBOR Apple M1 Max · macOS · Go 1.27.4 GOMAXPROCS=1 · median of 3 runs × 400 ms the same in-memory value for every codec encoding/json → map[string]any fxamacker/cbor v2.10.0, preferred serialization (shortest ints/floats) → map[string]any JSON Binary Go reference codec, CRC32C on → map[string]any gzip compress/gzip, default level // corpus: 12 public JSON test documents (simdjson / nativejson-benchmark) object records twitter, citm_catalog, github_events, update-center, gsoc-2018, apache_builds, instruments, random numeric data canada, marine_ik, mesh, numbers map keys: JSON and JSON Binary sort them; CBOR (unsorted mode) does not
  18. {} JSON binary Benchmarks Headline Numbers −61% −12% 4.0× 1.5×

    smaller smaller faster faster Payload size vs JSON Gzipped, vs JSON + gzip Decode vs encoding/json Encode vs encoding/json CBOR −23% CBOR +28% CBOR 2.6× CBOR 4.8× · CBOR wins Geometric mean over 12 public JSON test documents, Go, single thread. Decoding into ordered objects instead of maps reaches 8.1× JSON speed.
  19. Payload Size JSON {} binary CBOR Encoded Bytes · %

    of JSON · Shorter Is Better JSON Binary JSON baseline JSON == 100% JSON 0% 25% 50% 75% 100% Object records twitter.json 86% 23% citm_catalog.json smaller than JSON 68% 22% github_events.json 92% 69% update-center.json 97% 36% apache_builds.json 69% instruments.json 10% random.json Object records shrink to 10%–69% of JSON 89% 60% gsoc-2018.json 89% 79% Numeric arrays & geometry 50% 50% 48% 48% canada.json marine_ik.json mesh.json 53% numbers.json 53% 0% 25% 50% 60% 82% 65% 60% 75% CBOR: 68%–97% on the same files Keys and object shapes are sent once; numeric data gains less 83% 29% 2.5× 100%
  20. JSON {} binary CBOR Payload Size After gzip · %

    of JSON + gzip · Shorter Is Better JSON Binary JSON baseline JSON + gzip = 100% JSON 0% 50% 100% 150% 200% 250% 300% Object records twitter.json 144% 83% citm_catalog.json 70% update-center.json gsoc-2018.json 44% 73% random.json gzip already removes most repeated keys, so the gap narrows 131% 131% 116% 116% apache_builds.json instruments.json vs JSON + gzip 161% 111% 111% 100% 100% 114% 99% 102% github_events.json 295% Numeric arrays & geometry 84% 84% 85% 85% canada.json 156% 156% 150% 150% marine_ik.json 97% 97% 92% 92% mesh.json numbers.json 0% 50% 100% Smaller than JSON + gzip on 9 of 12; larger on apache_builds, marine_ik, numbers CBOR + gzip is larger than JSON + gzip on 10 of 12 115% 73% −12% 116% 116% 115% 115% 150% 200% 250% 300%
  21. Decode Speed JSON {} binary CBOR × Faster than encoding/json

    · Longer Is Better JSON Binary JSON baseline JSON == 1× JSON 1× 0× 1× 2× 3× 4× 5× 6× 7× 8× 9× Object records 2.0× twitter.json 1.5× citm_catalog.json github_events.json 4.2× 2.3× 2.3× 2.1× 2.1× 2.8× gsoc-2018.json 1.6× apache_builds.json 3.3× Faster than CBOR on 10 of 12; CBOR wins on canada, mesh 7.4× Fewer bytes to scan, binary numbers, keys resolved once per message 3.6× 1.7× random.json Object records: 2.3×–7.4× faster; CBOR 1.5×–2.8× 3.1× 1.9× instruments.json faster decode 3.9× 2.0× update-center.json 3.4× Numeric arrays & geometry canada.json 3.2× 3.2× 3.3× 3.3× marine_ik.json 4.4× 3.9× mesh.json 4.4× 5.1× 6.9× numbers.json 0× 1× 2× 3× 4× 4.0× 5× 6× 7× 8.1× 8× 9×
  22. Encode Speed JSON {} binary CBOR × Faster than encoding/json

    · Longer Is Better JSON Binary JSON baseline JSON == 1× JSON 1× 0× 1× 2× 3× 4× 5× 6× 7× 8× Object records twitter.json 3.8× 1.1× citm_catalog.json github_events.json 0.8× update-center.json 1.3× apache_builds.json 4.1× CBOR encodes faster on 12 of 12 (4.8× JSON) 4.1× Slower than encoding/json on github_events, update-center, canada 3.0× 0.9× gsoc-2018.json faster encode 3.0× 1.2× 2.9× 1.3× 4.5× 4.5× 4.1× 4.1× instruments.json random.json 3.3× 1.9× The encoder pre-scans the whole tree to build its tables: the price of smaller, faster-to-read payloads Numeric arrays & geometry canada.json 6.4× 0.6× marine_ik.json 6.1× 1.5× mesh.json 8.7× ▸ 8.7× 2.2× numbers.json 6.7× 0× 1× 2× 3× 1.5× 4× 5× 6× 7× 19.6× ▸ 19.6× 8×
  23. {} Benchmarks JSON binary Object Records in Absolute Numbers size

    decode time decode allocs JSON CBOR JSON Binary JSON CBOR JSON Binary JSON CBOR JSON Binary twitter.json 460 KB 393 KB 106 KB 5.10 ms 2.49 ms 1.20 ms 37,789 31,838 11,508 citm_catalog.json 489 KB 334 KB 108 KB 9.82 ms 6.56 ms 4.26 ms 114,243 109,114 74,358 github_events.json 52 KB 48 KB 36 KB 0.42 ms 0.21 ms 0.11 ms 3,892 3,698 2,083 update-center.json 525 KB 465 KB 315 KB 6.18 ms 3.15 ms 1.87 ms 58,539 53,820 30,699 gsoc-2018.json 2.93 MB 2.86 MB 1.07 MB 12.8 ms 4.60 ms 1.72 ms 64,282 68,256 22,307 apache_builds.json 93 KB 82 KB 64 KB 1.00 ms 0.64 ms 0.33 ms 11,559 12,346 6,224 instruments.json 106 KB 84 KB 11 KB 1.97 ms 1.05 ms 0.55 ms 18,490 12,681 4,763 random.json 451 KB 376 KB 130 KB 7.48 ms 4.36 ms 2.23 ms 78,412 70,760 32,367 Orange = best in each group. Decoded to map[string]any; allocations per decode from Go's benchmark counters.
  24. {} JSON binary Trade-Offs When Not to Use It //

    tiny payloads: fixed framing dominates, CBOR wins (bytes) JSON CBOR JSON Binary [{"a":10,"b":20},{"a":20,"b":30}] 33 16 23 +4 CRC [{"a":10,"b":20},{"a":30,"c":40}] 33 17 27 +4 CRC [1,200,-3,70000] 16 10 18 +4 CRC Prefer something else when — Payloads are tiny or one-off: 6 bytes of header + 4 bytes of CRC — Humans must read the wire, or every client must parse it with no library — Data must be streamed: the encoder needs the whole value up front — Encode speed matters most: CBOR encoded faster on all 12 test documents
  25. {} JSON ▸ JSON data model, plus raw bytes ▸

    Keys, shapes and repeated strings sent once ▸ One-byte tags for small values ▸ Integrity and decode limits built in ▸ Smallest payloads; fastest decode on object records Draft v1 · format may still change · reference codecs in Go, Dart and TypeScript binary