CBOR vs JSON: Comprehensive Format Comparison

Performance benchmarks, size comparisons, and practical use case recommendations

Published: December 2025 • 10 min read

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

FeatureJSONCBOR
EncodingText (UTF-8)Binary
Human ReadableYesNo (requires tools)
File SizeBaseline20-50% smaller
Parsing SpeedModerate2-3x faster
Data Types6 basic types20+ types (binary, dates, etc.)
Browser SupportNativeRequires library
DebuggingEasy (text editor)Requires hex viewer/tools
Best ForWeb APIs, configsIoT, 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)

JSON:87 bytes
CBOR:52 bytes
Savings:40% (35 bytes)

Array of 100 Objects

JSON:8,532 bytes
CBOR:4,276 bytes
Savings:50% (4,256 bytes)

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

1
Benchmark Current Performance: Measure current JSON payload sizes, parsing times, and bandwidth costs to establish baseline metrics.
2
Test with Sample Data: Convert representative payloads to CBOR and measure actual size reduction and performance improvement for your use case.
3
Pilot Implementation: Start with a single, non-critical endpoint or service. Monitor error rates, performance, and system impact.
4
Support Both Formats: Implement content negotiation (Accept: application/cbor) to support both JSON and CBOR clients during transition.
5
Gradual Rollout: Expand CBOR usage based on measured improvements. Maintain JSON for public APIs unless clients explicitly request CBOR.

Conversion and Testing Tools

Technical Specifications