# \[Solved\] Empty templated array is invalid JSON

**URL:** <https://forums.losant.com/t/solved-empty-templated-array-is-invalid-json/656>\
**Category:** Bug Report\
**Created:** [November 7, 2017, 9:03pm UTC](https://forums.losant.com/t/solved-empty-templated-array-is-invalid-json/656 "2017-11-07T21:03:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Brian\_Ritter](https://avatars.discourse-cdn.com/v4/letter/b/e5b9ba/32.png) [@Brian\_Ritter](https://forums.losant.com/u/Brian_Ritter)\
**Post date:** [November 7, 2017, 9:03pm UTC](https://forums.losant.com/t/solved-empty-templated-array-is-invalid-json/656/1 "2017-11-07T21:03:47Z")

</div>

In my workflow, when a templated value in the “Custom Page Data JSON Template” is an empty array, I get an InvalidJsonError. This can be tested by making a function node with the following code:

`payload.deviceList = [];`

and then set up the Endpoint Reply as:

 ![image](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/1X/f8f2e67c48469ee34a29b6acca1c599d3eccd152.png)

If an empty array is used in the JSON Template instead of {{deviceList}}, it works as expected with no error, which leads me to believe the error is unintended.

 ![image](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/1X/670576c0d1759b21ec011dad181b7f9b0114dcb9.png)

---

<div class="post-metadata">

**Author:** ![Dylan\_Schuster](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/dylan_schuster/32/2850_2.png) [@Dylan\_Schuster](https://forums.losant.com/u/Dylan_Schuster)\
**Post date:** [November 7, 2017, 9:20pm UTC](https://forums.losant.com/t/solved-empty-templated-array-is-invalid-json/656/2 "2017-11-07T21:20:17Z")

</div>

In your JSON Template, change {{deviceList}} to {{jsonEncode deviceList}} and that should do the trick.

Without the [jsonEncode format helper](https://docs.losant.com/workflows/accessing-payload-data/#format-helpers) in front of it, your reference is being evaluated as a string (probably spitting out “[object Object]”) hence the failure.

We’ll look into whether there’s a more intuitive way to reference this value, as at first glance we were a little baffled as well. Let us know if you have any more questions.

---

<div class="post-metadata">

**Author:** ![Brian\_Ritter](https://avatars.discourse-cdn.com/v4/letter/b/e5b9ba/32.png) [@Brian\_Ritter](https://forums.losant.com/u/Brian_Ritter)\
**Post date:** [November 7, 2017, 9:40pm UTC](https://forums.losant.com/t/solved-empty-templated-array-is-invalid-json/656/3 "2017-11-07T21:40:38Z")

</div>

Yep that works, thanks.
