# Change Node issue with JSONata

**URL:** <https://discourse.nodered.org/t/change-node-issue-with-jsonata/13648>\
**Category:** General\
**Created:** [24 July 2019 11:25 UTC](https://discourse.nodered.org/t/change-node-issue-with-jsonata/13648 "2019-07-24T11:25:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![nomi](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nomi/32/10378_2.png) [@nomi](https://discourse.nodered.org/u/nomi)\
**Post date:** [24 July 2019 11:25 UTC](https://discourse.nodered.org/t/change-node-issue-with-jsonata/13648/1 "2019-07-24T11:25:09Z")

</div>

Hi,  
I have a issue with the following Node-Red flow 🙂

```auto
[{"id":"5f0904d0.61fd5c","type":"tab","label":"tests","disabled":false,"info":""},{"id":"21d27fc5.dbd3c","type":"inject","z":"5f0904d0.61fd5c","name":"Result 1","topic":"","payload":"{\"CollectionsContainer\":[[{\"FirstName\":\"NOMI\",\"PersonAddress\":{\"Country\":\"FR\",\"Department\":\"\"},\"PersonContact\":{\"EmailAddress\":\"NOMI@MAIL.COM\",\"Fax\":\"\",\"Mobile\":\"\",\"Phone\":\"\"},\"PersonLogin\":{\"CodePin1\":\"\",\"CodePin2\":\"\",\"CodePin3\":\"\",\"CodePin4\":\"\",\"Password1\":\"\",\"Password2\":\"\",\"Password3\":\"\",\"Password4\":\"\",\"User1\":\"xxxxxx\",\"User2\":\"\",\"User3\":\"\",\"User4\":\"\"}}]],\"PageNumber\":1,\"PageSize\":1,\"ProcessingTime\":\"PT0.0400035S\",\"TotalNumber\":19996,\"TotalNumberRequest\":0,\"success\":true,\"OperationResult\":{\"Status\":\"SDK_OK\",\"Message\":null,\"SystemMessage\":null,\"StackTrace\":null}}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":380,"y":140,"wires":[["74e774c1.d17acc"]]},{"id":"35963010.0ea44","type":"inject","z":"5f0904d0.61fd5c","name":"Result 0","topic":"","payload":"{\"CollectionsContainer\":[[]],\"PageNumber\":1,\"PageSize\":0,\"ProcessingTime\":\"PT0.0440019S\",\"TotalNumber\":19995,\"TotalNumberRequest\":0,\"success\":true,\"OperationResult\":{\"Status\":\"SDK_OK\",\"Message\":null,\"SystemMessage\":null,\"StackTrace\":null}}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":380,"y":180,"wires":[["74e774c1.d17acc"]]},{"id":"74e774c1.d17acc","type":"change","z":"5f0904d0.61fd5c","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\t \"topic\": topic,\t \"count\": $.$count(CollectionsContainer[0]),\t \"toto\": $.$count(CollectionsContainer[0]) = 0 ? CollectionsContainer[0][0].FirstName : \"\"\t}","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":580,"y":160,"wires":[["4508bc09.aea804"]]},{"id":"4508bc09.aea804","type":"debug","z":"5f0904d0.61fd5c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":730,"y":160,"wires":[]}]

```

In the change node, I made a JSONata query:

```auto
{
   "topic": topic,
   "count": $.$count(CollectionsContainer[0]),
   "toto": $.$count(CollectionsContainer[0]) = 0 ? CollectionsContainer[0][0].FirstName : ""
}

```

The goal is to populate "toto", depending the array size of collectionsContainers.

FYI : the JSON data come from a web service o I can not modify it

Thanks

---

<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:** [24 July 2019 12:45 UTC](https://discourse.nodered.org/t/change-node-issue-with-jsonata/13648/2 "2019-07-24T12:45:24Z")

</div>

Try this

```auto
{ 
   "topic": topic,
   "count": $count(payload.CollectionsContainer[0]),
   "toto": $count(payload.CollectionsContainer[0]) = 0 ? payload.CollectionsContainer[0][0].FirstName : "bah"
}

```

---

<div class="post-metadata">

**Author:** ![nomi](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nomi/32/10378_2.png) [@nomi](https://discourse.nodered.org/u/nomi)\
**Post date:** [24 July 2019 12:55 UTC](https://discourse.nodered.org/t/change-node-issue-with-jsonata/13648/3 "2019-07-24T12:55:15Z")

</div>

> [@zenofmud](#):
>
> { "topic": topic, "count": $count(payload.CollectionsContainer[0]), "toto": $count(payload.CollectionsContainer[0]) = 0 ? payload.CollectionsContainer[0][0].FirstName : "bah" }

Thanks you; Its ok now.  
I understand my mistake. On inject node, the out flow was the "payload" object.  
So in input in the change node, I need to parse the payload.  
Correct ?

---

<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:** [24 July 2019 16:02 UTC](https://discourse.nodered.org/t/change-node-issue-with-jsonata/13648/4 "2019-07-24T16:02:03Z")

</div>

To be honest, I'm not a jsonata expert, I just played with it and decided to try what ended up working 😊
