wire / wire-format / bson-document
BSON (Binary JSON) documents are a sequence of typed elements followed by a null terminator. Each element: 1-byte type code, NUL-terminated field name (cstring), then the value (encoding depends on type). The document is prefixed by a 4-byte little-endian total size (including itself and the terminator).
aka: BSON document structure
spec: BSON specification (bsonspec.org)
BSON (Binary JSON) documents are a sequence of typed elements followed by a null terminator. Each element: 1-byte type code, NUL-terminated field name (cstring), then the value (encoding depends on type). The document is prefixed by a 4-byte little-endian total size (including itself and the terminator).
| field | size | meaning |
|---|---|---|
| Document size | 4 bytes | Total size of the document in bytes, including this field and the trailing 0x00. Little-endian. |
| Element (repeated) | variable | 1-byte type + cstring field name + value (type-specific encoding). |
| Terminator | 1 byte | 0x00. |
example:
16 00 00 00 02 6e 61 6d 65 00 06 00 00 00 4a 6f 68 6e 00 00
Document {"name": "John"}: size 22, type 0x02 string, field 'name', value 'John'
agent: curl -H 'accept: application/json' wire.phall.io/wire-format/bson-document
or /wire-format/bson-document.json