Usar CBOR codificación para compact binary JSON
CBOR (Concise Binary Objeto Representation, RFC 8949) es un binary serialization formatear para JSON-como datos, smaller y faster than JSON.
- 1
CBOR encodes JSON-like data (objects, arrays, strings, numbers, booleans, null) in binary. It is smaller than JSON (no quotes, no delimiters, compact integer encoding) and faster to parse (no text scanning). It also supports types JSON lacks: byte strings, dates, bignums.
- 2 Codificador Base64 →
After encoding data to CBOR (binary), encode the result as base64 for transport through text-only channels (HTTP, JSON fields, logs). The receiver decodes base64 to bytes, then decodes CBOR to the original data structure.
- 3 Decodificador Base64 →
Decodificar the base64 to recover the CBOR bytes, then decode CBOR to the original data. This two-step process (base64 → CBOR → data) is common when CBOR must transit text-based protocols.
- 4
Use CBOR when: payload size matters (IoT, mobile), parsing speed is critical, or you need binary data (byte arrays) without base64 inflation. For web APIs, JSON is still the default — CBOR requires content negotiation (Accept: application/cbor). Use it for internal services and constrained environments.
Preguntas frecuentes
- CBOR vs MessagePack?
- Both are binary JSON formats. CBOR is an IETF standard (RFC 8949) with a richer type system (tags, simple values). MessagePack is faster but less extensible. Choose CBOR for standards compliance and extensibility; MessagePack for raw speed.
- Is CBOR smaller than JSON?
- Typically 20-50% smaller for the same data, depending on content. Strings and large integers benefit most. For data with many small integers or booleans, the savings are larger due to CBOR's compact integer encoding.