# How to pass Json Data from "function node" to "template node"

**URL:** <https://discourse.nodered.org/t/how-to-pass-json-data-from-function-node-to-template-node/46030>\
**Category:** Meta\
**Created:** [21 May 2021 11:00 UTC](https://discourse.nodered.org/t/how-to-pass-json-data-from-function-node-to-template-node/46030 "2021-05-21T11:00:35Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![vinaykumar.v](https://avatars.discourse-cdn.com/v4/letter/v/958977/32.png) [@vinaykumar.v](https://discourse.nodered.org/u/vinaykumar.v)\
**Post date:** [21 May 2021 11:00 UTC](https://discourse.nodered.org/t/how-to-pass-json-data-from-function-node-to-template-node/46030/1 "2021-05-21T11:00:35Z")

</div>

Hi, I am Vinay

I am not understanding How to pass Json data from "function node" to "template node".

My sample Json data is below

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

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/d/adc68ed2e3ac3ad3cb6f9196b3c6450c0a489e44.png)  
I am placing Json data in function node and I should fetch that Json data into Template Node

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [21 May 2021 11:07 UTC](https://discourse.nodered.org/t/how-to-pass-json-data-from-function-node-to-template-node/46030/2 "2021-05-21T11:07:11Z")

</div>

Attach a debug node after the function.

Then read this page in the docs that will explain how to use the debug panel to find the right path to any data item.

Pay particular attention to the part about the buttons that appear under your mouse pointer when you over hover a debug message property in the sidebar.

![BX00Cy7yHi](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/d/bd1f333a9e043b061b39917c328b0094d3e52d30.gif)

[https://nodered.org/docs/user-guide/messages](https://nodered.org/docs/user-guide/messages)

Then once you have copied the path, paste that into the {{mustache}} in the template

Also, read the built in help for the template node.

---

<div class="post-metadata">

**Author:** ![vinaykumar.v](https://avatars.discourse-cdn.com/v4/letter/v/958977/32.png) [@vinaykumar.v](https://discourse.nodered.org/u/vinaykumar.v)\
**Post date:** [21 May 2021 11:24 UTC](https://discourse.nodered.org/t/how-to-pass-json-data-from-function-node-to-template-node/46030/4 "2021-05-21T11:24:01Z")

</div>

Hi  
I have copied the path and pasted in template using below command

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/c/4ca67896a12ff7aa744196ace99e04d9799ae75a.png)

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

I have used both but it is not getting

In console it is showing unexpected identifier

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [21 May 2021 11:24 UTC](https://discourse.nodered.org/t/how-to-pass-json-data-from-function-node-to-template-node/46030/5 "2021-05-21T11:24:13Z")

</div>

> [@vinaykumar.v](#):
>
> console.log({{payload.Students}})
> 
> In console it is showing unexpected identifier

It would.

You asked about the template node. The function node doesn't use mustache.

Also, in a function node, you need to specify the msg e.g...

```auto
node.log(msg.payload.Students)

```

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [21 May 2021 11:35 UTC](https://discourse.nodered.org/t/how-to-pass-json-data-from-function-node-to-template-node/46030/6 "2021-05-21T11:35:03Z")

</div>

If you want to list the array items the template mustache syntax woulbe be as below  
example flow

```auto
[{"id":"1b38a685.e629e9","type":"inject","z":"c74669a0.6a34f8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"student\":[{\"name\":\"tom\",\"class\":10},{\"name\":\"john\",\"class\":10}],\"employee\":[{\"name\":\"tim\",\"class\":10},{\"name\":\"jane\",\"class\":10}]}","payloadType":"json","x":190,"y":2360,"wires":[["bff1f319.af36a8"]]},{"id":"bff1f319.af36a8","type":"template","z":"c74669a0.6a34f8","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"Students\n{{#payload.student}}\n Name {{name}} Class {{class}}\n{{/payload.student}}\n\nEmployees\n{{#payload.employee}}\n Name {{name}} Class {{class}}\n{{/payload.employee}}","output":"str","x":350,"y":2360,"wires":[["4f6e9447.bba25c"]]},{"id":"4f6e9447.bba25c","type":"debug","z":"c74669a0.6a34f8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":570,"y":2360,"wires":[]}]

```

template

```auto
Students
{{#payload.student}}
 Name {{name}} Class {{class}}
{{/payload.student}}

Employees
{{#payload.employee}}
 Name {{name}} Class {{class}}
{{/payload.employee}}

```

object used, as you failed to supply one that can be copied

```auto
{
    "student": [
        {
            "name": "tom",
            "class": 10
        },
        {
            "name": "john",
            "class": 10
        }
    ],
    "employee": [
        {
            "name": "tim",
            "class": 10
        },
        {
            "name": "jane",
            "class": 10
        }
    ]
}

```

[edit After looking at your other posts, i doubt what you want to do (not that I fully understan) is possible as the console.log is server side and the code in the template I suspect will be client side. But as you do not explain what exactly you want to do one can only guess.  
here is another example but I doubt it will do what you want. If you want more help i think you will need to explain more clearly what you are attempting to do.

```auto
[{"id":"1b38a685.e629e9","type":"inject","z":"c74669a0.6a34f8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"student\":[{\"name\":\"tom\",\"class\":10},{\"name\":\"john\",\"class\":10}],\"employee\":[{\"name\":\"tim\",\"class\":10},{\"name\":\"jane\",\"class\":10}]}","payloadType":"json","x":110,"y":2360,"wires":[["b4039d87.784778"]]},{"id":"b4039d87.784778","type":"change","z":"c74669a0.6a34f8","name":"","rules":[{"t":"set","p":"payload.student","pt":"msg","to":"$string(payload.student)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":280,"y":2320,"wires":[["bff1f319.af36a8"]]},{"id":"bff1f319.af36a8","type":"template","z":"c74669a0.6a34f8","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"<script>\nconsole.log({{{payload.student}}})\n</script>","output":"str","x":370,"y":2360,"wires":[["4f6e9447.bba25c"]]},{"id":"4f6e9447.bba25c","type":"debug","z":"c74669a0.6a34f8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":530,"y":2360,"wires":[]}]

```

]

---

<div class="post-metadata">

**Author:** ![vinaykumar.v](https://avatars.discourse-cdn.com/v4/letter/v/958977/32.png) [@vinaykumar.v](https://discourse.nodered.org/u/vinaykumar.v)\
**Post date:** [21 May 2021 11:43 UTC](https://discourse.nodered.org/t/how-to-pass-json-data-from-function-node-to-template-node/46030/7 "2021-05-21T11:43:06Z")

</div>

How to access same Json data into script tag of mustache

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [20 June 2021 11:43 UTC](https://discourse.nodered.org/t/how-to-pass-json-data-from-function-node-to-template-node/46030/8 "2021-06-20T11:43:22Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
