Free Unlock your 1‑hour consultancy—schedule your session today! »

· Eduardo Vieira · IIoT  · 1 min read

MQTT Payload Formats: JSON, Binary, and Protobuf for IIoT

Discover when to use JSON, binary formats, or Protobuf for your MQTT messages in industrial environments.

MQTT Payload Formats: JSON, Binary, and Protobuf for IIoT

Choosing the payload format impacts performance, interoperability, and ease of development.

JSON (Plain Text)

  • Lightweight and human-readable; ideal for prototypes and debugging.
  • Widely supported across all languages.
  • Cons: larger size, slower parsing.
{"sensor_id":"S1","value":23.5,"unit":"°C"}

Binary

  • Smaller size; useful on bandwidth-constrained links.
  • Use struct or C structs to define the layout.
  • Cons: less readable, risk of endianness errors.
import struct
# sensor_id:uint8, value:float32
payload = struct.pack('<Bf', 1, 23.5)

Protobuf

  • Strongly typed, compact structures.
  • Define a schema in .proto and generate client/server code.
  • Cons: requires code generation and version management.

.proto:

syntax = "proto3";
message SensorData {
  uint32 sensor_id = 1;
  float value = 2;
  string unit = 3;
}
from sensor_pb2 import SensorData
msg = SensorData(sensor_id=1, value=23.5, unit="°C")
payload = msg.SerializeToString()

In the next post, we’ll analyze the differences between MQTT v3.1.1 and v5, and how to leverage the latest version’s new features.

Back to Blog

Related Posts

View All Posts »