# Payload message size in bytes

**URL:** https://discourse.nodered.org/t/payload-message-size-in-bytes/8755
**Category:** General
**Created:** [8 March 2019 22:02 UTC](https://discourse.nodered.org/t/payload-message-size-in-bytes/8755 "2019-03-08T22:02:55Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![sanserg](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sanserg/32/5472_2.png) [@sanserg](https://discourse.nodered.org/u/sanserg)
#### Post date: [8 March 2019 22:02 UTC](https://discourse.nodered.org/t/payload-message-size-in-bytes/8755/1 "2019-03-08T22:02:56Z")

</div>

Hi  
is there a way to see the payload (JSON) message size in bytes using node-red ?

Thanks

---

<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 March 2019 22:17 UTC](https://discourse.nodered.org/t/payload-message-size-in-bytes/8755/2 "2019-03-08T22:17:00Z")

</div>

Is the payload a string or what? You said JSON but JSON format implies it is a string. Perhaps you actually mean it is a javascript object in which case I suspect the answer is 'not easily' if not 'no'.  
If you don't know what it is then feed it into a debug node and show us what it says.

**[Edit]** Plus you have asked for payload message size, but the payload is not a message. Did you mean message.payload size or do you mean the size of a message containing this payload, or perhaps something else?

---

<div class="post-metadata">

### Author: ![sanserg](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sanserg/32/5472_2.png) [@sanserg](https://discourse.nodered.org/u/sanserg)
#### Post date: [8 March 2019 22:42 UTC](https://discourse.nodered.org/t/payload-message-size-in-bytes/8755/3 "2019-03-08T22:42:28Z")

</div>

Hi colin, sorry maybe was not clear...I am using the watson iot node and I am receiving messages from the platform. the message is a json payload that I wish to monitor the size in bytes (probably using a function).  
this is an example of the payload that I see in the debug window:

msg.payload : Object

object

camera\_congelado: 28.2

camera\_fria\_umidade: 62.5

camera\_fria: 28.2

date: "2019-03-08 19:40:06.933612"

tempo\_total: 0

count\_porta: 0

rendimento: 0

porta: true

camera\_congelado\_umidade: 62.5

fail: false

local: "17784"

tempo\_porta: 87

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [8 March 2019 23:04 UTC](https://discourse.nodered.org/t/payload-message-size-in-bytes/8755/4 "2019-03-08T23:04:02Z")

</div>

As Colin indicated trying to define the length of an object is a bit tricky. But you would get an indication by taking a string version of the object, e.g.

`msg.payload = JSON.stringify(msg.payload).length;`

This would include any necessary escape characters and quotes so is the same as the length of the object per se - but may be good enough ?

---

<div class="post-metadata">

### Author: ![sanserg](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sanserg/32/5472_2.png) [@sanserg](https://discourse.nodered.org/u/sanserg)
#### Post date: [9 March 2019 00:04 UTC](https://discourse.nodered.org/t/payload-message-size-in-bytes/8755/5 "2019-03-09T00:04:14Z")

</div>

excellent!

it worked...that is exactly what I was looking for!

thank you all!
