# \[IGN-6092\]Array in Expression Transform

**URL:** <https://forum.inductiveautomation.com/t/ign-6092-array-in-expression-transform/59766>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [May 19, 2022, 5:33am UTC](https://forum.inductiveautomation.com/t/ign-6092-array-in-expression-transform/59766 "2022-05-19T05:33:56Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![kgamble](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kgamble/32/8019_2.png) [@kgamble](https://forum.inductiveautomation.com/u/kgamble)\
**Post date:** [May 19, 2022, 5:33am UTC](https://forum.inductiveautomation.com/t/ign-6092-array-in-expression-transform/59766/1 "2022-05-19T05:33:56Z")

</div>

When I need to show a value that might not always be present, often I will just do coalesce statements in expressions like `coalesce({view.params.myOptionalParam}, '')` to show the value without an overlay if its not present (I do want the overlay if its present and bad quality)

However when I need to do this for a list or object I have only really found it possible through a runScript, is this really the only way?

Array:  
`coalesce({view.params.myListParam}, runScript("[]"))`

Object:  
`coalesce({view.params.myDictParam}, runScript("{}"))`

I would like to think that since perspective is so heavily built with objects and arrays there is a cleaner way to do this? Almost feels like there should just be a simple set of two expressions in perspective for `Array()` and `Object()` that take params to build the two or something.

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [May 19, 2022, 10:25am UTC](https://forum.inductiveautomation.com/t/ign-6092-array-in-expression-transform/59766/2 "2022-05-19T10:25:33Z")

</div>

Not easier or cleaner, but I guess if you wanted to avoid using `runScript` you could make empty array/object session props and return those instead ?

I kinda hope there’s a better way though.

---

<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:** [May 19, 2022, 4:31pm UTC](https://forum.inductiveautomation.com/t/ign-6092-array-in-expression-transform/59766/3 "2022-05-19T16:31:55Z")

</div>

> [@kgamble](#):
>
> Almost feels like there should just be a simple set of two expressions in perspective for `Array()` and `Object()` that take params to build the two or something.

That's an interesting idea.

Literal `[]` and `{}` are probably not going to happen, but I could see `arrayOf` and `objectOf` functions (or something similar).

Outside of this coalesce example, can you name any times you would have wanted to build an array or object entirely within an expression? Not to say that it's not a good idea, I'm just curious what the use cases would be.

---

<div class="post-metadata">

**Author:** ![kgamble](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kgamble/32/8019_2.png) [@kgamble](https://forum.inductiveautomation.com/u/kgamble)\
**Post date:** [May 19, 2022, 9:01pm UTC](https://forum.inductiveautomation.com/t/ign-6092-array-in-expression-transform/59766/4 "2022-05-19T21:01:59Z")

</div>

> [@paul-griffith](#):
>
> Outside of this coalesce example, can you name any times you would have wanted to build an array or object entirely within an expression?

Most use cases I can immediately think of I could solve with an expression structure, its just the default typing that I can't. For me its primarily to do the same thing as a `dict.get(myVal, defaultVal)` so that I don't have components erroring out from receiving `null`s instead of empty objects or lists.

But I would guess that with how deeply intertwined with perspective arrays and objects are, there have got to be other uses I am not thinking about.

EDIT: In order to do what is mentioned above with an expression structure, I would need to do an expression structure with my value, and then another with the default structure, and then do an expression transform afterwards that coalesces them together. Still feels a bit extra like the `runScript`

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [May 19, 2022, 9:33pm UTC](https://forum.inductiveautomation.com/t/ign-6092-array-in-expression-transform/59766/5 "2022-05-19T21:33:44Z")

</div>

Today I found myself needing to create a test array for the Tree component with a binding. Realising that the expression language couldn’t do it I set the expression to `null` and then applied a script transform which didn’t even look at `value` but just generated the dictionary with Python. (So I guess I have a workaround?!)

---

<div class="post-metadata">

**Author:** ![kgamble](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kgamble/32/8019_2.png) [@kgamble](https://forum.inductiveautomation.com/u/kgamble)\
**Post date:** [May 19, 2022, 10:20pm UTC](https://forum.inductiveautomation.com/t/ign-6092-array-in-expression-transform/59766/6 "2022-05-19T22:20:16Z")

</div>

I actually just helped another engineer that could have used this.

He had a popup that needed a list of tag paths, and a specific view that called it and only ever was going to provide one tag path.

So instead of just having his parameter of tag path, in order to provide the popup what he needed he would indirect `view.params.tagPath` into another object that was just structured as a list with a binding on index `0` to read the parameter. This could have been a lot easier if he could just use an expression of something like `arrayOf({view.params.tagPath})` and then it would have cut down on unnecessary middle man bindings slowing things down. I think that’s where this would shine, is the ability to remove extra bindings and transforms for small data manipulations.

---

<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:** [May 19, 2022, 10:30pm UTC](https://forum.inductiveautomation.com/t/ign-6092-array-in-expression-transform/59766/7 "2022-05-19T22:30:27Z")

</div>

I’m sold, I made an internal feature ticket for it. I can’t guarantee it’ll be picked up, but I’ll make the case 🙂

---

<div class="post-metadata">

**Author:** ![ShaneH](https://avatars.discourse-cdn.com/v4/letter/s/3e96dc/32.png) [@ShaneH](https://forum.inductiveautomation.com/u/ShaneH)\
**Post date:** [October 19, 2023, 10:47pm UTC](https://forum.inductiveautomation.com/t/ign-6092-array-in-expression-transform/59766/8 "2023-10-19T22:47:58Z")

</div>

this seemed like it should work to return a list:

jsonGet("{'fruit':['Apples','Oranges','Grapes']}",'fruit')

instead, it seems to just return:

['Apples','Oranges','Grapes']

as a string?

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [October 20, 2023, 5:48am UTC](https://forum.inductiveautomation.com/t/ign-6092-array-in-expression-transform/59766/9 "2023-10-20T05:48:30Z")

</div>

> [@ShaneH](#):
>
> ['Apples','Oranges','Grapes']

That's odd. When I try it all the single-quotes show up in the binding preview as double-quotes - so it's not handling it as a literal string yet a script transform with `return type(value)` shows `class org.python.core.PyUnicode` as though it is a string!?

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [October 20, 2023, 7:08am UTC](https://forum.inductiveautomation.com/t/ign-6092-array-in-expression-transform/59766/10 "2023-10-20T07:08:04Z")

</div>

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/1/5/1563533a3dbe65c96d70d651f2cba33070d3d5c4.png)
