hZqr — JSON in a single QR code
A document that carries itself on paper: a prescription, a ticket, a patient summary or a machine configuration. No network, no server and no account — the data is in the ink.
A QR code holds at most about 3 kB. Ordinary compression gets a typical JSON document part of the way there. hZqr gets the rest with trained dictionaries: the encoder tries every dictionary in its library on the document and keeps the one that saves the most.
How far it goes
The reference document, step by step (measured with the earlier catalog):
| step | size | fits in one QR code? |
|---|---|---|
| the JSON, pretty-printed | 53 kB | no |
| minified | 32 kB | no |
| brotli, maximum setting | about 4 kB | no |
| hZqr profile: trained dictionary | 2,737 bytes | yes, version 40 |
Honest numbers
Figures measured on a dictionary's own training examples flatter it, so they are not the ones quoted. What counts is documents the dictionaries have never seen. The first three rows are from the earlier catalog:
| measured on | hZqr payload as share of plain compression |
|---|---|
| the catalog's synthetic examples | 56 % |
| independent test set: real API responses and handwritten documents | 75 % |
| held-out set, written afterwards, measured once | 73.6 %, no failures |
| today's library, after a leakage audit (median) | 75.2 % |
So in practice, a quarter smaller than the best plain compression, and that quarter is often what decides whether a document fits in a code at all. The held-out set was written after the last bugs had been fixed and measured exactly once, so the figure could not be tuned. Only 11 % of its words occur anywhere in a dictionary.
The leakage audit is worth its own line: it found duplicates and near-copies between training and test data, and removing them took the median saving from 31.0 % down to 24.8 %. Both numbers are published; the size of the correction is the point.
The dictionary library
63 dictionaries, 2.06 MB in total: 50 for JSON and 13 for content that is not JSON. They are not named after document types. They are clusters of real documents, kept only if they measurably save bytes.
That replaced an earlier catalog of 1,000 type-named profiles (25 families × 8 subtypes × 5 languages), and the comparison is the reason:
| earlier catalog | today's library | |
|---|---|---|
| dictionaries | 1,000 | 63 |
| storage | 9.3 MB | 2.06 MB |
| median payload, 299 held-out documents | 662 B | 330 B |
| on the old catalog's own document types | 590 B | 486 B |
Fifty dictionaries capture 99 % of everything a larger library could achieve. Because there are so few, the encoder measures all 50 for real in 715 ms instead of guessing from a shortlist. A standard dictionary costs 3 characters of header in the code, down from 13. The 13 non-JSON slots were trained on 1,991 real documents, mostly XML, and save 23.0 % on 399 held-out ones.
Printed codes name their dictionary. Dictionaries are immutable and versioned, and the code says which one it needs. Replacing the 1,000 was a deliberate one-time break. The old set stays published in hzqr-catalog, so any code made with it can still be decoded.
Four ways to encode, and the tool picks
Standard (the text as is), packed, profile (dictionary plus schema) and link (the data lives on a server and the code carries only the address). The tool measures every alternative for real and only offers the ones that work. Only the link type reveals the content to anyone, and every result says out loud whether it was decoded locally or fetched.
Three implementations
The web, a C++ CLI and Python, verified to read each other's codes in both directions. The Android app carries the dictionaries inside it and decodes catalog and packed codes in airplane mode.
Open
The earlier 1,000-profile catalog is public in hzqr-catalog under CC0; today's 63-dictionary library and the code are not yet published. Anyone who wants to join, build a profile or test against their own documents is welcome to get in touch — see Open source and joining in.