# Json expression

**URL:** <https://discourse.nodered.org/t/json-expression/8896>\
**Category:** General\
**Created:** [12 March 2019 20:30 UTC](https://discourse.nodered.org/t/json-expression/8896 "2019-03-12T20:30:43Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![niclas.w82](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/niclas.w82/32/31813_2.png) [@niclas.w82](https://discourse.nodered.org/u/niclas.w82)\
**Post date:** [12 March 2019 20:30 UTC](https://discourse.nodered.org/t/json-expression/8896/1 "2019-03-12T20:30:43Z")

</div>

Hi. Is it possible to get rid of one of the function nodes. I want to combine the two messages sia\_code and sia\_address in the same function node. I want the output message to be 13ZO

/Niclas

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [12 March 2019 20:33 UTC](https://discourse.nodered.org/t/json-expression/8896/2 "2019-03-12T20:33:33Z")

</div>

Hi @niclas.w82

Your question is missing some context. Which function nodes are you referring to? Is there a previous topic on the forum with more background to your question?

---

<div class="post-metadata">

**Author:** ![niclas.w82](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/niclas.w82/32/31813_2.png) [@niclas.w82](https://discourse.nodered.org/u/niclas.w82)\
**Post date:** [12 March 2019 20:39 UTC](https://discourse.nodered.org/t/json-expression/8896/3 "2019-03-12T20:39:24Z")

</div>

Sorry forgot the picture

 ![48](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/3/349fc20a339672c64710931e604a48099914c5f9.png)

---

<div class="post-metadata">

**Author:** ![niclas.w82](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/niclas.w82/32/31813_2.png) [@niclas.w82](https://discourse.nodered.org/u/niclas.w82)\
**Post date:** [13 March 2019 21:24 UTC](https://discourse.nodered.org/t/json-expression/8896/4 "2019-03-13T21:24:05Z")

</div>

Anyone knows if this is possible?

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [13 March 2019 21:25 UTC](https://discourse.nodered.org/t/json-expression/8896/5 "2019-03-13T21:25:45Z")

</div>

Yes. You can do that in a change node with JSONata. Have a go yourself, I think you will find it fairly easy since you only need to create a simple string output.

---

<div class="post-metadata">

**Author:** ![niclas.w82](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/niclas.w82/32/31813_2.png) [@niclas.w82](https://discourse.nodered.org/u/niclas.w82)\
**Post date:** [14 March 2019 19:41 UTC](https://discourse.nodered.org/t/json-expression/8896/6 "2019-03-14T19:41:19Z")

</div>

Ok. JSONata is something totally new to me. But tried this. Any idea?

 ![43](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/4/4a978324b4e34598b011c3278e053b9d9ed56685.png)

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [14 March 2019 20:07 UTC](https://discourse.nodered.org/t/json-expression/8896/7 "2019-03-14T20:07:58Z")

</div>

You are some way out in your object/property reference I'm afraid.

You would, I think - hard to say without more context - at least need:

```
msg.payload.data.sia.sia_code

```

And the same for sia\_address.

To get the exact object reference, in the debug window, over the line containing the code or address entries, you will see some small icons appear to the right of the line. Click on the one that looks like `>_` and it will tell you that it has copied the path.

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

Paste that into your code.

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [14 March 2019 20:12 UTC](https://discourse.nodered.org/t/json-expression/8896/8 "2019-03-14T20:12:01Z")

</div>

Hi @niclas.w82

the JSONata Expressions can only be used in the `Change` node, where the input is set to the `Expression` type.

You are showing a screenshot of a `Function` node - that uses JavaScript.

So rather than use `&` to join strings, you need to use `+`.

But you also need to get the reference to the property right as @TotallyInformation describes above.

---

<div class="post-metadata">

**Author:** ![niclas.w82](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/niclas.w82/32/31813_2.png) [@niclas.w82](https://discourse.nodered.org/u/niclas.w82)\
**Post date:** [14 March 2019 20:38 UTC](https://discourse.nodered.org/t/json-expression/8896/9 "2019-03-14T20:38:13Z")

</div>

Getting closer. Tried with + but it doesn't work in the test. Now I get the result I want but in the debug window it just look like this " " and I cannot understand why?

 ![33](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/7/733ba5fd0e5175c85b45362778fb4bd8e3425b78.png)

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [14 March 2019 20:39 UTC](https://discourse.nodered.org/t/json-expression/8896/10 "2019-03-14T20:39:30Z")

</div>

In the Expression editor you are use `data.sia.sia_code`... but your previous screenshot showed that data was under `msg.payload`. So you should use `payload.data.sia.sia_code` in your expression - just as @TotallyInformation suggested.

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [14 March 2019 20:40 UTC](https://discourse.nodered.org/t/json-expression/8896/11 "2019-03-14T20:40:27Z")

</div>

Because your example message is NOT what is incoming. You've only shown the msg.payload part.

You need the example to look like:

```auto
{"payload": {"status": ...... } }
```

---

<div class="post-metadata">

**Author:** ![niclas.w82](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/niclas.w82/32/31813_2.png) [@niclas.w82](https://discourse.nodered.org/u/niclas.w82)\
**Post date:** [14 March 2019 20:43 UTC](https://discourse.nodered.org/t/json-expression/8896/12 "2019-03-14T20:43:36Z")

</div>

Finally solved!

Thank you all for your help!!!

/Niclas
