# jsonGet vs jsonDecode

**URL:** <https://forum.inductiveautomation.com/t/jsonget-vs-jsondecode/96838>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [October 4, 2024, 5:15pm UTC](https://forum.inductiveautomation.com/t/jsonget-vs-jsondecode/96838 "2024-10-04T17:15:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![justin.brzozoski](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justin.brzozoski/32/13452_2.png) [@justin.brzozoski](https://forum.inductiveautomation.com/u/justin.brzozoski)\
**Post date:** [October 4, 2024, 5:15pm UTC](https://forum.inductiveautomation.com/t/jsonget-vs-jsondecode/96838/1 "2024-10-04T17:15:04Z")

</div>

I am trying to convert some scripting transforms into expressions, and I've bumped into the fact that the `jsonGet` expression seems to leave complex objects as strings. For example, this expression returns the string `[1,3,5]`:

```python
jsonGet("{'aaa':[1,3,5],'bbb':7}","aaa")

```

But this script returns an array-like object:

```python
return system.util.jsonDecode("{'aaa':[1,3,5],'bbb':7}")['aaa']

```

Am I missing something here, or is jsonGet lazy? Any time I try to make it return something more complex than just a single int/string/float/bool it just returns a JSON substring.

And while I've got eyes here, is the syntax for the `jsonGet` path based on any public syntax I can look at? It's simple enough that I can fake it, but I was hoping it had fancier features like JSONPath to aggregate sub-fields.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [October 4, 2024, 5:17pm UTC](https://forum.inductiveautomation.com/t/jsonget-vs-jsondecode/96838/2 "2024-10-04T17:17:45Z")

</div>

It's not supposed to return encoded/complex objects, it extracts JSON from JSON. The expression language in general also can't operate on arrays or complex objects.

edit: mmm, I think that's how it's supposed to work with arrays, anyway.

edit2: yes, seems so, but it's a little more nuanced because it actually depends on the type you pass in.

This is the relevant part of the unit tests if it helps you imagine:

```python
if (json instanceof String) {
    assertEquals("[2,1,0]", jsonGet(json, "widget_array[1].d"));
} else if (json instanceof DocumentElement) {
    assertEquals(parseDocument("[2,1,0]"), jsonGet(json, "widget_array[1].d"));
} else if (json instanceof JsonElement) {
    assertEquals(parseDocument("[2,1,0]"), jsonGet(json, "widget_array[1].d"));
}

```

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [October 4, 2024, 5:25pm UTC](https://forum.inductiveautomation.com/t/jsonget-vs-jsondecode/96838/3 "2024-10-04T17:25:15Z")

</div>

So, to summarize my rambling:

If you feed the function a String that happens to be JSON you get a String that happens to be JSON back.

If you feed it a DocumentElement (i.e. the value from a Document tag) you get a DocumentElement back.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [October 4, 2024, 5:55pm UTC](https://forum.inductiveautomation.com/t/jsonget-vs-jsondecode/96838/4 "2024-10-04T17:55:07Z")

</div>

You might like the `jsonDecode()` expression function I recently added to my Integration Toolkit. Returns the complex object you expect. (Not yet documented, as there's more, related, coming.)
