# How to encode a JSON packet like {"id":{"noData":True}} (Sigfox downlink type)

**URL:** <https://discourse.nodered.org/t/how-to-encode-a-json-packet-like-id-nodata-true-sigfox-downlink-type/2625>\
**Category:** General\
**Created:** [28 August 2018 08:15 UTC](https://discourse.nodered.org/t/how-to-encode-a-json-packet-like-id-nodata-true-sigfox-downlink-type/2625 "2018-08-28T08:15:49Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![svi](https://avatars.discourse-cdn.com/v4/letter/s/e56c9b/32.png) [@svi](https://discourse.nodered.org/u/svi)\
**Post date:** [28 August 2018 08:15 UTC](https://discourse.nodered.org/t/how-to-encode-a-json-packet-like-id-nodata-true-sigfox-downlink-type/2625/1 "2018-08-28T08:15:49Z")

</div>

I want to encode the downlink packet of a Sigfox device.  
Two type of packets can be sent:

response={"21f400":{"noData":True}}  
response={"21f400":{"downlinkData":"dadadadadadadada"}}

I have done it before in python this way, and it worked fine:

```
		response={device:{"noData":True}}
		response=json.dumps(response)

```

In node- red I have tried different options , the last:  
msg.payload={deviceId:{"noData":true}}  
But It doesn't work.

Any other ideas? 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:** [28 August 2018 08:48 UTC](https://discourse.nodered.org/t/how-to-encode-a-json-packet-like-id-nodata-true-sigfox-downlink-type/2625/2 "2018-08-28T08:48:23Z")

</div>

> [@svi](#):
>
> msg.payload={deviceId:{"noData":true}}

If you do that and return the message and send to a debug node what do you see?

---

<div class="post-metadata">

**Author:** ![svi](https://avatars.discourse-cdn.com/v4/letter/s/e56c9b/32.png) [@svi](https://discourse.nodered.org/u/svi)\
**Post date:** [28 August 2018 11:52 UTC](https://discourse.nodered.org/t/how-to-encode-a-json-packet-like-id-nodata-true-sigfox-downlink-type/2625/3 "2018-08-28T11:52:02Z")

</div>

Hi Colin and thanks.

Debug node shows:  
packetType : msg.payload : Object

```
object

deviceId: object

downlinkData: "0201020000000000"

```

I clarify that deviceId is defined in the node as:  
var deviceId = flow.get('deviceId')

---

<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:** [28 August 2018 12:56 UTC](https://discourse.nodered.org/t/how-to-encode-a-json-packet-like-id-nodata-true-sigfox-downlink-type/2625/4 "2018-08-28T12:56:42Z")

</div>

I can't see how you get that from  
`msg.payload = {deviceId:{"noData":true"}}`  
I think I am missing something about what you are doing.  
Explain again exactly what you are trying to get in the payload, with an example.

---

<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:** [28 August 2018 13:17 UTC](https://discourse.nodered.org/t/how-to-encode-a-json-packet-like-id-nodata-true-sigfox-downlink-type/2625/5 "2018-08-28T13:17:55Z")

</div>

Ah, I think I see a bit of what you are trying to do, if you want  
`msg.payload={"21f400":{"noData":True}}`  
where you already have something like  
`deviceID = "21f400"`  
Then you can say

```auto
msg.payload = {}
msg.payload[deviceID] = {noData: true}

```

---

<div class="post-metadata">

**Author:** ![svi](https://avatars.discourse-cdn.com/v4/letter/s/e56c9b/32.png) [@svi](https://discourse.nodered.org/u/svi)\
**Post date:** [29 August 2018 09:23 UTC](https://discourse.nodered.org/t/how-to-encode-a-json-packet-like-id-nodata-true-sigfox-downlink-type/2625/6 "2018-08-29T09:23:37Z")

</div>

Thank you!!

That worked, finally!
