# Size limit ? of a JSON object ? (Arduino -\> MQTT -\> Node-Red)

**URL:** <https://discourse.nodered.org/t/size-limit-of-a-json-object-arduino-mqtt-node-red/17686>\
**Category:** General\
**Created:** [8 November 2019 17:25 UTC](https://discourse.nodered.org/t/size-limit-of-a-json-object-arduino-mqtt-node-red/17686 "2019-11-08T17:25:04Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![alexandre-romain](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/alexandre-romain/32/13181_2.png) [@alexandre-romain](https://discourse.nodered.org/u/alexandre-romain)\
**Post date:** [8 November 2019 17:25 UTC](https://discourse.nodered.org/t/size-limit-of-a-json-object-arduino-mqtt-node-red/17686/1 "2019-11-08T17:25:04Z")

</div>

Hi there !

I'm facing a weird problem which I don't understand (well, I'm still some king of a newbee ...).

I'm sending a JSON formatted string to a MQTT broker (local, hosted on a Debian Buster server where Node-Red also resides) with an Arduino and retrieve it with Node-Red.

The code is like follows :

String jsonPayload = "{"DHT\_1\_t":"";  
jsonPayload += t\_1;  
jsonPayload +="","DHT\_1\_h":"";  
jsonPayload += h\_1;  
jsonPayload +="","YF-S201\_1":"";  
jsonPayload += l\_min\_1;  
jsonPayload +="","phR\_1":"";  
jsonPayload += phR\_1;  
jsonPayload +="","PIR\_1":"";  
jsonPayload += pir\_1;  
jsonPayload +="","AS-103\_1":"";  
jsonPayload += Irms;  
jsonPayload +="","MQ-2\_1":"";  
jsonPayload += mq2\_1Value;  
//jsonPayload +="","MQ-7\_1":"";  
//jsonPayload += mq7\_1Value;  
//jsonPayload +="","MQ-135\_1":"";  
//jsonPayload += mq135\_1Value;  
jsonPayload +=""}";

Like this, it works. But if I uncomment the 4 lines .. it stops working ... I don't get anything anymore (while the serial output from the arduino is correct, it's not a problem with the Arduino sketch.

Any idea ? Are there some limitations I missed ?

Thnaks in advance for your valuable help

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [8 November 2019 18:13 UTC](https://discourse.nodered.org/t/size-limit-of-a-json-object-arduino-mqtt-node-red/17686/2 "2019-11-08T18:13:28Z")

</div>

> [@alexandre-romain](#):
>
> /jsonPayload +="","MQ-7\_1":"";

That doesn't look like valid code though it is difficult to be certain what sort of quotes they are. Some of the earlier lines don't look valid either. In the editor do you see an error indicator against that line? If not then feed the output into a debug node and see what it looks like before and after uncommenting the lines.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [8 November 2019 19:23 UTC](https://discourse.nodered.org/t/size-limit-of-a-json-object-arduino-mqtt-node-red/17686/3 "2019-11-08T19:23:23Z")

</div>

What mqtt library are you using?

don't you need a backslash to escape the double quotes? So your first line should be  
`String jsonPayload = "{\"DHT_1_t\":\"";`  
it may be that they were removed because you didn't enclose your code with three back tic's (```) before and after your code.

p.s. if you are using PubSubClient then I beleive the limit is 128 which you can change

```auto
// MQTT_MAX_PACKET_SIZE : Maximum packet size
#ifndef MQTT_MAX_PACKET_SIZE
#define MQTT_MAX_PACKET_SIZE 384 // need to fix this here, because this define cannot be overruled within the Arduino sketch...
#endif

```

---

<div class="post-metadata">

**Author:** ![i8beef](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/i8beef/32/3161_2.png) [@i8beef](https://discourse.nodered.org/u/i8beef)\
**Post date:** [8 November 2019 19:43 UTC](https://discourse.nodered.org/t/size-limit-of-a-json-object-arduino-mqtt-node-red/17686/4 "2019-11-08T19:43:07Z")

</div>

Just for anyone who finds this by title later: If your using the PubSubClient for the Arduino, they DO have a limit:

> The maximum message size, including header, is **128 bytes** by default. This is configurable via `MQTT_MAX_PACKET_SIZE`

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [8 November 2019 21:56 UTC](https://discourse.nodered.org/t/size-limit-of-a-json-object-arduino-mqtt-node-red/17686/5 "2019-11-08T21:56:49Z")

</div>

> [@alexandre-romain](#):
>
> The code is like follows

Just realised that Is Arduino code not node-red code. Has @i8beef's post sorted it?

---

<div class="post-metadata">

**Author:** ![alexandre-romain](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/alexandre-romain/32/13181_2.png) [@alexandre-romain](https://discourse.nodered.org/u/alexandre-romain)\
**Post date:** [9 November 2019 00:00 UTC](https://discourse.nodered.org/t/size-limit-of-a-json-object-arduino-mqtt-node-red/17686/6 "2019-11-09T00:00:33Z")

</div>

> [@i8beef](#):
>
> MQTT\_MAX\_PACKET\_SIZE

It must be the problem !! I will check this tomorrow morning.

Thanks a lot already !!!

---

<div class="post-metadata">

**Author:** ![alexandre-romain](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/alexandre-romain/32/13181_2.png) [@alexandre-romain](https://discourse.nodered.org/u/alexandre-romain)\
**Post date:** [9 November 2019 16:34 UTC](https://discourse.nodered.org/t/size-limit-of-a-json-object-arduino-mqtt-node-red/17686/7 "2019-11-09T16:34:49Z")

</div>

It worked perfectly !!

Thanks a lot for your help !!
