# Expression length of JSON object/array

**URL:** <https://forum.inductiveautomation.com/t/expression-length-of-json-object-array/32982>\
**Category:** Ignition\
**Tags:** ignition80, perspective\
**Created:** [March 10, 2020, 5:17pm UTC](https://forum.inductiveautomation.com/t/expression-length-of-json-object-array/32982 "2020-03-10T17:17:49Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![rcrownover](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/rcrownover/32/17805_2.png) [@rcrownover](https://forum.inductiveautomation.com/u/rcrownover)\
**Post date:** [March 10, 2020, 5:17pm UTC](https://forum.inductiveautomation.com/t/expression-length-of-json-object-array/32982/1 "2020-03-10T17:17:49Z")

</div>

Does anyone know if its possible to get the length of a JSON array or JSON object via the expression language in Perspective? Unfortunately, both `len({property})` and `{property.length}` don’t work. I can at least test for empty-ness via: [Expression to test for empty json query result](http://forum.inductiveautomation.com/t/expression-to-test-for-empty-json-query-result/30068/3?u=rcrownover). But if possible I would like to get a size back so I don’t have to use a script (and thus add to gateway load).

---

<div class="post-metadata">

**Author:** ![kirsten.chambers](https://avatars.discourse-cdn.com/v4/letter/k/48db29/32.png) [@kirsten.chambers](https://forum.inductiveautomation.com/u/kirsten.chambers)\
**Post date:** [March 10, 2020, 5:56pm UTC](https://forum.inductiveautomation.com/t/expression-length-of-json-object-array/32982/2 "2020-03-10T17:56:56Z")

</div>

Unfortunate that the Expression language’s `len()` doesn’t work. I took the liberty of creating an [idea post here](https://ideas.inductiveautomation.com/ignition-features-and-ideas/p/update-expression-functions-for-perspective-json) to throw the ball into IA’s court just in case it hasn’t come up yet.

A script is an easy way to work around this–Python’s `len()` function will work as expected. If you’re skittish about performance of an expression vs. a script on your gateway load, consider that evaluating expressions would have to be performed somewhere, too (i.e., the gateway). No free ~~lunch~~ computation, after all.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [March 10, 2020, 6:18pm UTC](https://forum.inductiveautomation.com/t/expression-length-of-json-object-array/32982/3 "2020-03-10T18:18:14Z")

</div>

Yeah, having `len`, `sum`, etc work with JSON objects is something on our radar, just hasn’t come back to the top of the pile yet.

---

<div class="post-metadata">

**Author:** ![rcrownover](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/rcrownover/32/17805_2.png) [@rcrownover](https://forum.inductiveautomation.com/u/rcrownover)\
**Post date:** [March 10, 2020, 6:39pm UTC](https://forum.inductiveautomation.com/t/expression-length-of-json-object-array/32982/4 "2020-03-10T18:39:04Z")

</div>

I guess I didn’t think through expressions also being evaluated on the gateway. That’s pretty obvious after a few seconds of thought.

It would be super cool if those could be interpreted by the browser on the client side.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [March 10, 2020, 6:49pm UTC](https://forum.inductiveautomation.com/t/expression-length-of-json-object-array/32982/5 "2020-03-10T18:49:53Z")

</div>

Well, aside from the technical hurdles of implementing the actual code expressions use in Javascript, it wouldn’t actually be any performance benefit - component properties and the like are already synchronized between the frontend and backend.
