Skip to content
BetterPass logo

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.

Side-by-side size comparison: the same data in JSON text format takes 42 bytes, while the MessagePack binary format takes only 27 bytes

Text vs Binary: Serialization Size Comparison

JSON (text) — 42 bytes

{"name":"Bob","age":30,"city":"NY"}

MessagePack (binary) — 27 bytes

\x83\xA4name\xA3Bob\xA3age\x1E\xA4city\xA2NY

FormatCompare Studio

Paste any JSON to see it encoded into every format live — real byte counts, computed in your browser.

JSONText · native125 B · 100% of JSON
MessagePackBinary · schemaless95 B · 76% of JSON
CBORBinary · RFC 8949100 B · 80% of JSON
BSONBinary · MongoDB143 B · 114% of JSON
ProtobufBinary · schema53 B · 42% of JSON

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.

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

Human-readable: JSON
Compact binary: MessagePack

High-Performance RPC / Microservices

gRPC, internal services, contract-first, codegen

Best: Protobuf
Alternative: MessagePack (schemaless)

MongoDB / Document Stores

Working with MongoDB, CosmosDB, DocumentDB

Native: BSON
Types: ObjectId, Date, Decimal128

Standards / IoT / Constrained

RFC compliance, embedded devices, extensibility

IETF Standard: CBOR (RFC 8949)
Extensible: Tags, custom types

MessagePack vs CBOR vs BSON vs Protobuf: Format Comparison Matrix

PropertyJSONMessagePackCBORBSONProtobuf
Schema RequiredNoNo (schemaless)No (schemaless)No (schemaless)Yes (.proto)
Type SystemString, Number, Bool, Null, Array, ObjectJSON + BinData, Timestamp, ExtJSON + BigInt, Decimal, Tags, ExtJSON + ObjectId, Date, BinData, Decimal128, Int64, Regex, CodeScalar (int32, bool, string, bytes) + Message, Enum, Map, Repeated
Encoding OverheadText (UTF-8)~20-30% vs JSON~20-30% vs JSON~10-20% vs JSONLowest (varints, no field names)
Parse Speed (relative)1x (baseline)2-5x faster2-5x faster2-3x faster5-10x faster
Schema EvolutionManual (version in payload)Ext types / manualTags / manualManualBuilt-in (field numbers, optional/required)
Code GenerationTypeScript interfacesLimitedLimitedLimitedFirst-class (protoc → Go, Java, Python, JS, etc.)
Human ReadableYesNo (binary)No (binary)No (binary)No (requires schema)
Streaming SupportNDJSONYes (length prefixes)Yes (indefinite length)YesYes (delimited)
StandardRFC 8259 (ECMA-404)Spec (github.com/msgpack)RFC 8949 (IETF)MongoDB specGoogle 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

  1. Define .proto schema
  2. Run protoc → generate code
  3. Use generated classes to serialize/deserialize
  4. 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

  1. Open MessagePack tool
  2. Paste JSON object → Encode
  3. Copy Base64 output → store in Redis
  4. Decode on read: Base64 → MessagePack → JSON

Inspect MongoDB Document

  1. Copy BSON from MongoDB shell/Compass
  2. Open BSON tool
  3. Decode → view JSON with ObjectId, Date, etc.
  4. Edit → Encode → update document

Protobuf Contract-First API

  1. Write service.proto in Protobuf tool
  2. Paste JSON request → Encode → binary payload
  3. Send to gRPC endpoint (grpcurl, postman)
  4. Decode response with same schema

CBOR for IoT/COAP

  1. Open CBOR tool
  2. Encode sensor data with semantic tags (datetime, UUID)
  3. Verify size savings vs JSON
  4. Test decode on target device firmware

Compare Payload Sizes

  1. Paste sample JSON in each tool
  2. Encode to MessagePack, CBOR, BSON
  3. Note byte counts in output
  4. Pick best ratio for your data shape

Debug gRPC Request

  1. Capture binary protobuf from network tab
  2. Open Protobuf with .proto
  3. Paste binary (Base64) → Decode
  4. 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

  1. Add Accept: application/msgpack header support
  2. Return Content-Type based on client Accept
  3. Keep JSON as fallback (default)
  4. Monitor: parse time, payload size, error rate
  5. 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-Type header
  • 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)

OperationJSON.parse@msgpack/msgpackcbor2.decodeprotobufjs.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 → Hashing

Password storage & salting with Bcrypt, Argon2, scrypt

Hashing → Encoding

Hex/base64 representation of hash digests

Encoding → Tokens

Base64URL in JWT

Tokens → Serialization

Protobuf for efficient token payload serialization