JSON payloads are readable, self-describing and easy to debug, but several times larger than the same readings packed as binary, which needs a decoder that knows the byte layout. MQTT 3.1.1 allows packets of up to 268,435,455 bytes, so the size limits that bite in practice come from client buffers, broker settings and radio frames.
I pick the format by the link and the battery first, then by who has to debug the messages. If the transport is still open, start with MQTT vs HTTP for IoT devices.
What is the maximum MQTT message size?
The protocol limit is 268,435,455 bytes, about 256 MB, per packet. The MQTT 3.1.1 specification encodes a packet’s Remaining Length in at most four bytes, and that sets the ceiling.
The limits you meet are far lower. A client library on a microcontroller usually works with a fixed buffer that has to hold the whole packet: header, topic name and payload. When a message outgrows it, the publish can fail with an error that is easy to miss. A broker can enforce its own maximum, and a long topic name eats into the same buffer.
How do you send JSON over MQTT?
Serialise the object to a UTF-8 string and publish its bytes; the subscriber that writes your history parses them back. MQTT does not look inside. The specification says “the content and format of the data is application specific”.
Two rules from RFC 8259 keep JSON portable. JSON exchanged between systems outside a closed ecosystem must be UTF-8, and only integers between -(2^53)+1 and 2^53-1 are interoperable, meaning implementations agree on their exact value, so a 64-bit counter or a long serial number is safer as a string. Keys travel with every message, so their length shows in the byte count:
| Payload | Bytes |
|---|---|
{"temperature":21.37,"humidity":48.2,"battery":3.61} | 52 |
{"t":21.37,"rh":48.2,"bat":3.61} | 32 |
| Binary: temperature as a signed 16-bit integer in hundredths, humidity as one byte in half percent (48.2 travels as 48.0), battery as an unsigned 16-bit integer in millivolts | 5 |
Should an IoT device send JSON or binary?
Send JSON when bandwidth and battery are cheap and many people read the messages; send binary when every byte costs airtime or battery. Concise Binary Object Representation (CBOR), defined in RFC 8949, sits between them: compact, and decodable without a schema, like JSON.
| Criterion | JSON | Packed binary |
|---|---|---|
| Size | Largest: keys travel with every message | Smallest: values only |
| Debugging | Readable in any log | Needs the decoder |
| Adding a field | Readers that skip unknown keys keep working | Both ends change the layout together |
| Decoder | Any JSON parser | Code written for that layout |
The radio frame is the hardest limit. In the EU863-870 band, the LoRaWAN Regional Parameters (RP002-1.0.3) allow at most 51 bytes of application payload at data rates DR0 to DR2, the slowest ones. The 52-byte JSON above does not fit, while the 5-byte binary fits ten times over. On those links the server runs a decoder per sensor model, a LoRaWAN payload codec. Constrained Application Protocol (CoAP) is softer: RFC 7252 names 1,024 bytes as a good upper bound for the payload when nothing is known about the path, to avoid IP fragmentation.
How do you convert a byte payload to a string?
Use the length that came with the message, not a terminating zero. An MQTT payload is a run of bytes whose length follows from the packet header, and nothing adds a null at the end, so C code that treats the buffer as a string reads past the payload.
Copy exactly that many bytes, add the terminator yourself, and decode as UTF-8 before parsing the JSON. A binary payload should never become a string at all: read each field at its offset, in the byte order both ends agreed on. Byte and word order are the same trap that catches 32-bit floats in Modbus register addressing.
Frequently asked questions
Can CBOR or another binary encoding go over MQTT?
Yes. MQTT 3.1.1 treats the payload as bytes whose content and format are application specific, so any encoding works. The subscriber has to know which one to expect, usually from the topic or from an agreement per device type.
Should timestamps go in the payload?
Put a timestamp in the payload when the device buffers readings or sends them late, so the receiver stores each reading at the time it was measured. A device that only sends live values can leave it out and let the receiver stamp the arrival time. In JSON, an ISO 8601 string is readable; in binary, a 32-bit Unix time is compact.
Can one device mix JSON and binary messages?
It can, if the receiver can tell them apart, for example by topic or by a leading type byte. I would avoid it on one topic: every consumer then needs both parsers, and a payload that starts with a brace by chance gets read as the wrong format.

