# In node red using JSONata the output is empty

**URL:** <https://discourse.nodered.org/t/in-node-red-using-jsonata-the-output-is-empty/8998>\
**Category:** General\
**Created:** [14 March 2019 19:47 UTC](https://discourse.nodered.org/t/in-node-red-using-jsonata-the-output-is-empty/8998 "2019-03-14T19:47:48Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![VIKRAMAS](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/vikramas/32/3955_2.png) [@VIKRAMAS](https://discourse.nodered.org/u/VIKRAMAS)\
**Post date:** [14 March 2019 19:47 UTC](https://discourse.nodered.org/t/in-node-red-using-jsonata-the-output-is-empty/8998/1 "2019-03-14T19:47:48Z")

</div>

The input I'm giving is

```auto
{ "payload": [{ "FirstName": "Fred", "Surname": "Smith", "Age": 28, "Address": { "Street": "Hursley Park", "City": "Winchester", "Postcode": "SO21 2JN" }, "Phone": [ { "type": "home", "number": "+44 203 5441234" }, { "type": "office", "number": "00 44 1962 001234" }, { "type": "mobile", "number": "0044 7777-001234" }] }, { "FirstName": "Freda", "Surname": "Smith", "Age": 25, "Address": { "Street": "Hursley Park", "City": "Winchester", "Postcode": "SO21 2JN" }, "Phone": [{ "type": "home", "number": "+44 203 9871234" }, { "type": "office", "number": "00 44 1962 998765" }, { "type": "mobile", "number": "0044 7777-098765" }] } ] }

```

The JSONata expression I'm using is  
`payload.{FirstName & ' ' & Surname:{"Phone":Phone{type:number}}}`

The out put displaying while testing is `[{ "Fred Smith": { "Phone": { "home": "+44 203 5441234", "office": "00 44 1962 001234", "mobile": "0044 7777-001234" } } }, { "Freda Smith": { "Phone": { "home": "+44 203 9871234", "office": "00 44 1962 998765", "mobile": "0044 7777-098765" } } }]`

But getting the output after injecting message is  
`{" ":{"Phone":{}}}`

The flow is  
`[{"id":"f97bd0c3.1907a","type":"tab","label":"Flow 9","disabled":false,"info":""},{"id":"7b267b3f.5f0964","type":"inject","z":"f97bd0c3.1907a","name":"","topic":"","payload":"{\"payload\":[{\"FirstName\":\"Fred\",\"Surname\":\"Smith\",\"Age\":28,\"Address\":{\"Street\":\"Hursley Park\",\"City\":\"Winchester\",\"Postcode\":\"SO21 2JN\"},\"Phone\":[{\"type\":\"home\",\"number\":\"+44 203 5441234\"},{\"type\":\"office\",\"number\":\"00 44 1962 001234\"},{\"type\":\"mobile\",\"number\":\"0044 7777-001234\"}]},{\"FirstName\":\"Freda\",\"Surname\":\"Smith\",\"Age\":25,\"Address\":{\"Street\":\"Hursley Park\",\"City\":\"Winchester\",\"Postcode\":\"SO21 2JN\"},\"Phone\":[{\"type\":\"home\",\"number\":\"+44 203 9871234\"},{\"type\":\"office\",\"number\":\"00 44 1962 998765\"},{\"type\":\"mobile\",\"number\":\"0044 7777-098765\"}]}]}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":90,"y":240,"wires":[["eb3145fa.7326b8"]]},{"id":"e1a4752d.b7a448","type":"debug","z":"f97bd0c3.1907a","name":"","active":true,"tosidebar":true,"console":true,"tostatus":false,"complete":"payload","x":350,"y":80,"wires":[]},{"id":"eb3145fa.7326b8","type":"change","z":"f97bd0c3.1907a","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.{FirstName & ' ' & Surname:{\"Phone\":Phone{type:number}}}","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":160,"y":80,"wires":[["e1a4752d.b7a448"]]}]`

Am I missing something.

---

<div class="post-metadata">

**Author:** ![shrickus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shrickus/32/517_2.png) [@shrickus](https://discourse.nodered.org/u/shrickus)\
**Post date:** [14 March 2019 20:11 UTC](https://discourse.nodered.org/t/in-node-red-using-jsonata-the-output-is-empty/8998/2 "2019-03-14T20:11:29Z")

</div>

Looks like your `inject` node is creating a payload that is an object with one field called "payload".  
Try changing your inject node to just include the array of data...

---

<div class="post-metadata">

**Author:** ![VIKRAMAS](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/vikramas/32/3955_2.png) [@VIKRAMAS](https://discourse.nodered.org/u/VIKRAMAS)\
**Post date:** [15 March 2019 06:21 UTC](https://discourse.nodered.org/t/in-node-red-using-jsonata-the-output-is-empty/8998/3 "2019-03-15T06:21:44Z")

</div>

I changed the inject node by removing payload attribute but still the result is same

`[{"id":"f97bd0c3.1907a","type":"tab","label":"Flow 9","disabled":false,"info":""},{"id":"7b267b3f.5f0964","type":"inject","z":"f97bd0c3.1907a","name":"","topic":"","payload":"[{\"FirstName\":\"Fred\",\"Surname\":\"Smith\",\"Age\":28,\"Address\":{\"Street\":\"Hursley Park\",\"City\":\"Winchester\",\"Postcode\":\"SO21 2JN\"},\"Phone\":[{\"type\":\"home\",\"number\":\"+44 203 5441234\"},{\"type\":\"office\",\"number\":\"00 44 1962 001234\"},{\"type\":\"mobile\",\"number\":\"0044 7777-001234\"}]},{\"FirstName\":\"Freda\",\"Surname\":\"Smith\",\"Age\":25,\"Address\":{\"Street\":\"Hursley Park\",\"City\":\"Winchester\",\"Postcode\":\"SO21 2JN\"},\"Phone\":[{\"type\":\"home\",\"number\":\"+44 203 9871234\"},{\"type\":\"office\",\"number\":\"00 44 1962 998765\"},{\"type\":\"mobile\",\"number\":\"0044 7777-098765\"}]}]","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":90,"y":240,"wires":[["eb3145fa.7326b8"]]},{"id":"e1a4752d.b7a448","type":"debug","z":"f97bd0c3.1907a","name":"","active":true,"tosidebar":true,"console":true,"tostatus":false,"complete":"payload","x":600,"y":240,"wires":[]},{"id":"eb3145fa.7326b8","type":"change","z":"f97bd0c3.1907a","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"{FirstName & ' ' & Surname:{\"Phone\":Phone{type:number}}}","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":300,"y":240,"wires":[["e1a4752d.b7a448"]]}]`

---

<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:** [15 March 2019 14:56 UTC](https://discourse.nodered.org/t/in-node-red-using-jsonata-the-output-is-empty/8998/4 "2019-03-15T14:56:20Z")

</div>

Place a debug node on the output of the inject node. Set the node to display the `complete msg object`. Deploy and press the inject and look at what comes out.

What do you notice about the data displayed?  
What are you trying to set the data to be?

---

<div class="post-metadata">

**Author:** ![shrickus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shrickus/32/517_2.png) [@shrickus](https://discourse.nodered.org/u/shrickus)\
**Post date:** [15 March 2019 17:53 UTC](https://discourse.nodered.org/t/in-node-red-using-jsonata-the-output-is-empty/8998/5 "2019-03-15T17:53:04Z")

</div>

I'm guessing that you are trying to set up your change node this way:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/8/8e6bc9b629f4665d0c76c352d9102c3c40551bfe.png)

Looks like you just missed the root `payload` in your expression... don't forget that the JSON body of your inject node will automatically be placed inside `msg.payload`, which is why you originally had it defined as `msg.payload.payload`

i added some spaces to your expression for readability, pasted your injected data into the test, and you can see the results are a single object with one property for each person. If my guess is not correct, please show us what else you need.

---

<div class="post-metadata">

**Author:** ![VIKRAMAS](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/vikramas/32/3955_2.png) [@VIKRAMAS](https://discourse.nodered.org/u/VIKRAMAS)\
**Post date:** [15 March 2019 18:29 UTC](https://discourse.nodered.org/t/in-node-red-using-jsonata-the-output-is-empty/8998/6 "2019-03-15T18:29:13Z")

</div>

Thank you ,By accessing through `msg.payload` in JSONata expression I am able to retrieve the result.
