Binary Serialization Tools — MessagePack, CBOR, BSON & Protobuf
Convert between JSON and binary serialization formats. All client-side, zero server exposure for your data. Choose the right format for your use case with the guide below.
What Is Data Serialization? JSON, Protobuf, and Binary Formats Explained
When a chat app sends a message, that message doesn't travel as a JavaScript object — it gets flattened into a stream of bytes first, then rebuilt on the other end. That's data serialization: converting in-memory data (objects, arrays, maps) into a format that can be stored, transmitted, and reconstructed later. The reverse process is called deserialization. Serialization formats fall into two broad categories: text-based formats like JSON and XML that are human-readable but larger, and binary formats like MessagePack, CBOR, BSON, and Protocol Buffers that are more compact and faster to parse but not directly readable. The choice of serialization format affects payload size, parsing speed, schema flexibility, and interoperability between systems.
JSON is the universal standard for web APIs — it is language-agnostic, human-readable, and supported natively by every modern programming language and browser. MessagePack is a schemaless binary JSON alternative that produces smaller payloads while preserving the same data model, making it ideal for latency-sensitive applications. CBOR (Concise Binary Object Representation, RFC 8949) offers better standard library support and extensibility than MessagePack, with specific optimizations for IoT and constrained environments. BSON is MongoDB's binary format that extends JSON with additional data types (ObjectId, Date, BinData, Decimal128). Protocol Buffers (Protobuf) requires a .proto schema definition but produces the smallest payloads and enables code generation and strict schema evolution — it is the standard for high-performance RPC systems like gRPC.
When choosing a serialization format, consider your priorities. For public REST APIs, JSON is the default choice for maximum interoperability. For internal microservices where performance matters, MessagePack or CBOR provide compact payloads without schema management overhead. For high-performance, contract-first systems (especially gRPC), Protobuf is the clear winner. For MongoDB workloads, BSON is unavoidable. All BetterPass serialization tools run entirely in your browser — your data is encoded and decoded locally with no server uploads, making them safe for working with sensitive information.
Text vs Binary: Serialization Size Comparison
JSON (text) — 42 bytes
MessagePack (binary) — 27 bytes
FormatCompare Studio
Paste any JSON to see it encoded into every format live — real byte counts, computed in your browser.
Encoded length vs the minified JSON baseline. Protobuf uses a fixed built-in Sample schema, so payloads that don't match it report n/a.
JSON Formatter
Validate, prettify, and minify JSON for API debugging and config inspection. Instant syntax checking with collapsible tree view and human-readable formatting.
MessagePack
Convert JSON to compact MessagePack binary for Redis, session stores, and real-time networking. 20-30% smaller payloads — drop-in binary replacement for JSON.
CBOR
Convert JSON to CBOR (RFC 8949) for IoT, constrained devices, and COAP protocols. Supports semantic tags, big integers, and indefinite-length encoding.
BSON
Convert JSON to BSON for MongoDB documents — supports ObjectId, Date, BinData, Decimal128, and Int64. Essential for inspecting and debugging MongoDB driver data.
Protobuf
Encode and decode Protocol Buffers using your own .proto schema directly in the browser. Ideal for gRPC debugging, contract-first API testing, and schema validation.
Choosing the Right Serialization Format
Serialization formats trade off readability, speed, size, and flexibility. The right choice depends on your use case:
1. General Purpose / Web APIs
JSON — Best for REST APIs, config files, and human-readable data interchange. Universal support across all languages and platforms. Text-based, UTF-8 encoded. Use when readability and broad interoperability are priorities.
MessagePack — Best for compact binary when you don't need a schema. Drop-in JSON replacement — same data model, 20-30% smaller, 2-5x faster to parse. Ideal for Redis values, session stores, and real-time game networking.
2. High-Performance RPC / Microservices
Protobuf — Best for gRPC, internal services, and contract-first APIs. Requires .proto schema but delivers smallest payloads and fastest parsing (5-10x JSON). Built-in schema evolution with field numbers. Code generation for Go, Java, Python, JS, and more.
3. MongoDB / Document Stores
BSON — MongoDB's native binary format. Adds types not in JSON: ObjectId, Date, BinData, Decimal128, Int64, Regex. Use when working with MongoDB drivers or needing these extended types. Not designed for general-purpose interchange.
4. Standards / IoT / Constrained Environments
CBOR (RFC 8949) — IETF standard for constrained devices. Extensible via semantic tags — supports datetime, UUID, MIME, and crypto types. Indefinite-length arrays/maps for streaming. Used in COAP, OSCORE, and EDHOC protocols.
Quick Format Selection
General Purpose / Web APIs
REST APIs, config files, debug logging, interop
High-Performance RPC / Microservices
gRPC, internal services, contract-first, codegen
MongoDB / Document Stores
Working with MongoDB, CosmosDB, DocumentDB
Standards / IoT / Constrained
RFC compliance, embedded devices, extensibility
MessagePack vs CBOR vs BSON vs Protobuf: Format Comparison Matrix
| Property | JSON | MessagePack | CBOR | BSON | Protobuf |
|---|---|---|---|---|---|
| Schema Required | No | No (schemaless) | No (schemaless) | No (schemaless) | Yes (.proto) |
| Type System | String, Number, Bool, Null, Array, Object | JSON + BinData, Timestamp, Ext | JSON + BigInt, Decimal, Tags, Ext | JSON + ObjectId, Date, BinData, Decimal128, Int64, Regex, Code | Scalar (int32, bool, string, bytes) + Message, Enum, Map, Repeated |
| Encoding Overhead | Text (UTF-8) | ~20-30% vs JSON | ~20-30% vs JSON | ~10-20% vs JSON | Lowest (varints, no field names) |
| Parse Speed (relative) | 1x (baseline) | 2-5x faster | 2-5x faster | 2-3x faster | 5-10x faster |
| Schema Evolution | Manual (version in payload) | Ext types / manual | Tags / manual | Manual | Built-in (field numbers, optional/required) |
| Code Generation | TypeScript interfaces | Limited | Limited | Limited | First-class (protoc → Go, Java, Python, JS, etc.) |
| Human Readable | Yes | No (binary) | No (binary) | No (binary) | No (requires schema) |
| Streaming Support | NDJSON | Yes (length prefixes) | Yes (indefinite length) | Yes | Yes (delimited) |
| Standard | RFC 8259 (ECMA-404) | Spec (github.com/msgpack) | RFC 8949 (IETF) | MongoDB spec | Google Protobuf (proto3) |
JSON
Design Philosophy
Universal data interchange format. Human-readable, language-agnostic, and ubiquitously supported. "The lingua franca of web APIs."
Key Features
- Text-based, UTF-8 encoded
- Types: string, number, bool, null, array, object
- Native browser support (JSON.parse/stringify)
- RFC 8259 / ECMA-404 standard
Best For
- REST APIs, config files, debug logging
- Any scenario needing human readability
- Maximum interoperability across platforms
MessagePack
Design Philosophy
Drop-in JSON replacement. Minimal spec, extremely simple implementation. "It's like JSON but fast and small."
Key Features
- Fixed-type encoding (no tags in stream)
- Single-byte prefixes for common types
- Extension types for custom data (msgpack-ext)
- Str 8/16/32, Bin 8/16/32, Array/Map 16/32
Best For
- Redis values, session stores
- Game networking, real-time apps
- Embedded systems (tiny parsers)
- Replacing JSON where schema not needed
CBOR (RFC 8949)
Design Philosophy
IETF standard. Extensible via tags. Self-describing. "JSON with binary efficiency and extensibility."
Key Features
- Major/minor type system (8 major types)
- Semantic tags (RFC 8949 §3): datetime, UUID, MIME, crypto, etc.
- Indefinite-length arrays/maps (streaming)
- Half-precision floats, big integers, decimals
Best For
- IoT, constrained environments (RFC 8949)
- COAP, OSCORE, EDHOC protocols
- Data requiring standard extensibility (tags)
- Interop with non-JS ecosystems (Go, Rust, C)
BSON (MongoDB)
Design Philosophy
Binary JSON for MongoDB. Adds rich data types while maintaining JSON-like document structure. "JSON with more types, in binary."
Extra Types
- ObjectId — unique document identifier
- Date — 64-bit UTC timestamp
- BinData — arbitrary binary data
- Decimal128 — high-precision decimal
- Int64 — 64-bit integer
- Regex, JavaScript Code, Timestamp
Best For
- MongoDB / CosmosDB / DocumentDB
- Applications needing extended data types
- Database-level driver communication
Protocol Buffers (proto3)
How It Works
- Define
.protoschema - Run
protoc→ generate code - Use generated classes to serialize/deserialize
- Wire format: field number + wire type + value
Wire Types
- Varint (int32, int64, bool, enum)
- 64-bit (fixed64, sfixed64, double)
- Length-delimited (string, bytes, embedded messages, packed repeated)
- 32-bit (fixed32, sfixed32, float)
Schema Evolution Rules
- Never change field numbers
- Never change wire types
- Add new fields with new numbers (optional)
- Remove fields → mark reserved
- Rename fields freely (number stays)
Common Workflows
JSON → MessagePack for Redis
- Open MessagePack tool
- Paste JSON object → Encode
- Copy Base64 output → store in Redis
- Decode on read: Base64 → MessagePack → JSON
Inspect MongoDB Document
- Copy BSON from MongoDB shell/Compass
- Open BSON tool
- Decode → view JSON with ObjectId, Date, etc.
- Edit → Encode → update document
Protobuf Contract-First API
- Write
service.protoin Protobuf tool - Paste JSON request → Encode → binary payload
- Send to gRPC endpoint (grpcurl, postman)
- Decode response with same schema
CBOR for IoT/COAP
- Open CBOR tool
- Encode sensor data with semantic tags (datetime, UUID)
- Verify size savings vs JSON
- Test decode on target device firmware
Compare Payload Sizes
- Paste sample JSON in each tool
- Encode to MessagePack, CBOR, BSON
- Note byte counts in output
- Pick best ratio for your data shape
Debug gRPC Request
- Capture binary protobuf from network tab
- Open Protobuf with .proto
- Paste binary (Base64) → Decode
- Inspect fields, fix contract mismatches
Migration Guide: JSON → Binary
When to Migrate
- API payload > 10KB and high throughput
- Mobile clients on slow networks
- Internal microservices (controlled endpoints)
- WebSocket/Server-Sent Events message volume
- Redis/Memcached value storage costs
Migration Strategy
- Add
Accept: application/msgpackheader support - Return
Content-Typebased on clientAccept - Keep JSON as fallback (default)
- Monitor: parse time, payload size, error rate
- Gradually shift internal services first
Client-Side Considerations
- @msgpack/msgpack (fastest JS decoder, 1.5MB)
- cbor2 (RFC 8949 compliant, 400KB)
- protobufjs (runtime, no build step, 200KB)
- @bufbuild/protobuf (modern, tree-shakeable)
- Bundle size vs parse speed tradeoff
Common Pitfalls
- Forgetting
Content-Typeheader - Double-encoding (binary → Base64 → JSON string)
- Schema drift in Protobuf (breaking consumers)
- MessagePack Ext types not portable across languages
- CBOR tags not understood by all decoders
Rough Performance Expectations (V8/Node.js)
| Operation | JSON.parse | @msgpack/msgpack | cbor2.decode | protobufjs.decode |
|---|---|---|---|---|
| Small obj (200B) | ~0.5 µs | ~0.3 µs | ~0.4 µs | ~1.2 µs |
| Medium (5KB) | ~5 µs | ~2 µs | ~3 µs | ~8 µs |
| Large (100KB) | ~80 µs | ~30 µs | ~40 µs | ~120 µs |
Numbers illustrative — benchmark with your data shapes. Network latency usually dominates for payloads < 10KB.
Live Benchmark Widget
Runs real encode + decode timing in your browser for every format. Results vary by machine — use them as a relative guide.
Shorter bars are faster. All computation is local; a fresh run replaces the numbers above.
Frequently Asked Questions
MessagePack and CBOR are schemaless binary JSON alternatives — they encode any JSON-like data without a predefined schema.
Protobuf requires a .proto schema definition, which gives you smaller payloads, code generation, and schema evolution.
MessagePack is more compact for small objects. CBOR has better standard library support and extensibility. Protobuf is best for high-performance RPC and contract-first APIs.
Related Tools — Explore the Full Toolchain
Starting from the top? Learn about password generation →
Password storage & salting with Bcrypt, Argon2, scrypt
Hex/base64 representation of hash digests
Base64URL in JWT
Protobuf for efficient token payload serialization