CBOR (Concise Binary Object Representation) and JSON (JavaScript Object Notation) serve the same fundamental purpose: representing structured data in a portable format. However, they differ significantly in encoding method, efficiency, and optimal use cases.
JSON uses human-readable text encoding, making it ideal for web APIs and configuration files. CBOR uses binary encoding, optimizing for size and processing speed at the cost of human readability. This comparison examines performance metrics, implementation considerations, and decision criteria for choosing between formats.
Both formats are standardized (JSON via ECMA-404, CBOR via RFC 8949) and have mature library support across programming languages. Test conversions using our JSON to CBOR andCBOR to JSON converters.
Quick Comparison Overview
| Feature | JSON | CBOR |
|---|---|---|
| Encoding | Text (UTF-8) | Binary |
| Human Readable | Yes | No (requires tools) |
| File Size | Baseline | 20-50% smaller |
| Parsing Speed | Moderate | 2-3x faster |
| Data Types | 6 basic types | 20+ types (binary, dates, etc.) |
| Browser Support | Native | Requires library |
| Debugging | Easy (text editor) | Requires hex viewer/tools |
| Best For | Web APIs, configs | IoT, mobile, security |
File Size Comparison
CBOR achieves smaller file sizes by eliminating text overhead. The size advantage increases with data complexity:
Simple Object (5 fields)
Array of 100 Objects
Bandwidth Impact Analysis
1,000 requests/day
JSON: 8.5 MB/day
CBOR: 4.3 MB/day
10,000 devices
JSON: 85 GB/day
CBOR: 43 GB/day
Annual Savings
10,000 devices
15.3 TB/year
Performance Benchmarks
Binary encoding provides CBOR with significant performance advantages in parsing, serialization, and memory efficiency:
Parsing Speed (1000 objects)
JSON Parsing:
125ms
CBOR Parsing:
45ms
2.8x faster
Serialization Speed (1000 objects)
JSON Serialization:
98ms
CBOR Serialization:
38ms
2.6x faster
CPU & Memory Impact
CPU Usage
JSON: 100% baseline
CBOR: ~35-40%
Memory Allocation
JSON: 100% baseline
CBOR: ~60-70%
Battery Impact
JSON: 100% baseline
CBOR: ~60-65%
Note: Benchmarks based on cbor-x (JavaScript) and standard JSON.parse/stringify on Node.js 20. Actual performance varies by implementation and hardware.
Data Type Support
CBOR extends JSON's data types with additional native support for binary data and specialized types:
JSON Data Types (6)
- •String:UTF-8 text only
- •Number:IEEE 754 double precision (±2^53)
- •Boolean:true or false
- •Null:Represents absence of value
- •Array:Ordered list of values
- •Object:Key-value pairs
Limitations: Binary data requires base64 encoding, dates must be strings, integers limited to ±2^53, no undefined type
CBOR Data Types (20+)
- ✓All JSON typesFull compatibility
- +Binary Data:Raw bytes without encoding
- +Integers:Up to ±2^64 and arbitrary precision
- +Timestamps:Native date/time representation
- +Tagged Values:UUID, base64url, MIME, regex, etc.
- +Undefined:Explicit undefined type
- +Float16/32/64:Precise numeric types
Advantages: No base64 overhead for binary, efficient date storage, extensible via tags, better numeric precision
Practical Encoding Examples
Comparison of common data structures in both formats:
Example 1: IoT Sensor Data
JSON (67 bytes)
{
"id": 101,
"temp": 22.5,
"humidity": 65,
"status": "active"
}CBOR Hex (42 bytes - 37% smaller)
A4 62 69 64 18 65 64 74 65 6D 70 F9 41 68 68 68 75 6D 69 64 69 74 79 18 41 66 73 74 61 74 75 73 66 61 63 74 69 76 65
Example 2: Array of Coordinates
JSON (89 bytes)
{
"points": [
{"x": 10, "y": 20},
{"x": 30, "y": 40},
{"x": 50, "y": 60}
]
}CBOR (45 bytes - 49% smaller)
A1 66 70 6F 69 6E 74 73 83 A2 61 78 0A 61 79 14 A2 61 78 18 1E 61 79 18 28 A2 61 78 18 32 61 79 18 3C
Example 3: Image Thumbnail (1KB binary)
JSON with base64 (1,368 bytes)
{
"image": "iVBORw0KGgoAAAANS...
[1024 bytes base64 encoded]
...UhEUgAAAAUA"
}Base64 encoding adds 33% overhead
CBOR binary (1,028 bytes - 25% smaller)
A1 65 69 6D 61 67 65 59 04 00 [raw 1024 bytes]
Raw binary, no encoding overhead
When to Use Each Format
Choose JSON For:
- →Public Web APIs
REST APIs consumed by external developers. Universal compatibility and no additional libraries required.
- →Configuration Files
Application settings that humans need to read and modify. Easy editing in text editors.
- →Development & Debugging
During development when inspecting data payloads. Readable in browser DevTools and logs.
- →Document Storage
Databases like MongoDB where JSON/JSONB is natively optimized and queryable.
- →Browser-Only Applications
Web apps where JSON.parse/stringify provides sufficient performance without additional dependencies.
- →Small Data Payloads
When data sizes are small (<1KB) and optimization provides minimal benefit.
Choose CBOR For:
- →IoT & Embedded Systems
Resource-constrained devices where bandwidth and battery life are critical. Sensors, wearables, industrial equipment.
- →Mobile Applications
Apps on metered connections or targeting markets with limited bandwidth. Reduces data costs for users.
- →Authentication Systems
WebAuthn implementations (required by standard). Security keys, biometric auth, passwordless login.
- →High-Frequency Data Transfer
Systems sending thousands of messages per second. Real-time analytics, telemetry, streaming data.
- →Binary Data Transmission
When payloads contain images, encrypted data, or other binary content. Avoids base64 encoding overhead.
- →Internal Microservices
Service-to-service communication where both ends support CBOR. Reduces latency and bandwidth costs.
Hybrid Strategy
Many production systems use JSON for public APIs (developer experience) and CBOR for internal communication (efficiency). This approach balances compatibility with performance. Convert between formats using our JSON to CBOR andCBOR to JSON tools.
Implementation Considerations
Library Support
JSON
- • JavaScript: Native (JSON.parse/stringify)
- • Python: Built-in json module
- • Java: Jackson, Gson, org.json
- • Go: encoding/json (standard library)
- • Rust: serde_json
- • All languages: Native or stdlib support
CBOR
- • JavaScript: cbor-x, cbor2
- • Python: cbor2, cbor
- • Java: com.fasterxml.jackson.dataformat.cbor
- • Go: fxamacker/cbor
- • Rust: serde_cbor, ciborium
- • All languages: Third-party libraries required
Migration Strategy
Conversion and Testing Tools
JSON to CBOR
Convert JSON to CBOR and compare file sizes
CBOR to JSON
Decode CBOR binary back to JSON format
CBOR Validator
Validate CBOR binary data structure
JSON Formatter
Format and beautify JSON before converting
JSON Validator
Validate JSON syntax before conversion
CBOR Formatter
Format CBOR diagnostic notation
Technical Specifications
- •RFC 8949: CBOR Specification - Official IETF standard defining CBOR format and encoding rules
- •ECMA-404: JSON Specification - Official JSON data interchange syntax standard
- •CBOR.io - Official CBOR website with implementations and tools
- •JSON.org - Introducing JSON by Douglas Crockford
- •RFC 7049: Original CBOR Specification - First CBOR standard (superseded by RFC 8949)
- •MDN Web Docs: JSON - Mozilla's comprehensive JSON documentation
- •W3C WebAuthn Standard - Web authentication standard using CBOR
- •CBOR on GitHub - Official CBOR GitHub organization with implementations
- •What is CBOR? - Introduction to CBOR format and use cases
- •What is JSON? - Complete guide to JSON format