# Parsing a JSON string

**URL:** <https://forum.inductiveautomation.com/t/parsing-a-json-string/61914>\
**Category:** Ignition\
**Tags:** scripting, ignition81, perspective\
**Created:** [July 14, 2022, 6:14pm UTC](https://forum.inductiveautomation.com/t/parsing-a-json-string/61914 "2022-07-14T18:14:14Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael.Usry](https://avatars.discourse-cdn.com/v4/letter/m/7c8e57/32.png) [@Michael.Usry](https://forum.inductiveautomation.com/u/Michael.Usry)\
**Post date:** [July 14, 2022, 6:14pm UTC](https://forum.inductiveautomation.com/t/parsing-a-json-string/61914/1 "2022-07-14T18:14:14Z")

</div>

I have a variable with this info:  
[{“lpn”:“00000709193070470712”,“location”:“1 1 2 1 1 5 1 “,“sku”:“01318”,“lot\_number”:“220528”,“qc\_status”:“PASS”,“timestamp”:1654020723000,“quantity”:35,“sub\_status”:“DONE”,“status”:“INDUCT”,“dest”:””,“reason\_code”:“Good Pallet”,“handstack”:“N”,“row\_locked”:0}]

I will have to pull each one out separately, but how do ‘lpn’. Sorry to the simply question but I’m new and I’ve not figure it out in 2 days.

---

<div class="post-metadata">

**Author:** ![Peter.Dmitriev](https://avatars.discourse-cdn.com/v4/letter/p/7ea924/32.png) [@Peter.Dmitriev](https://forum.inductiveautomation.com/u/Peter.Dmitriev)\
**Post date:** [July 14, 2022, 7:48pm UTC](https://forum.inductiveautomation.com/t/parsing-a-json-string/61914/2 "2022-07-14T19:48:17Z")

</div>

variable = [{“lpn”:“00000709193070470712”,“location”:“1 1 2 1 1 5 1”}]

print variable[0][“lpn”]

---

<div class="post-metadata">

**Author:** ![Michael.Usry](https://avatars.discourse-cdn.com/v4/letter/m/7c8e57/32.png) [@Michael.Usry](https://forum.inductiveautomation.com/u/Michael.Usry)\
**Post date:** [July 14, 2022, 8:04pm UTC](https://forum.inductiveautomation.com/t/parsing-a-json-string/61914/3 "2022-07-14T20:04:42Z")

</div>

Thanks, but I’m still getting … object is unsubscriptable

---

<div class="post-metadata">

**Author:** ![code\_skin](https://avatars.discourse-cdn.com/v4/letter/c/43a26b/32.png) [@code\_skin](https://forum.inductiveautomation.com/u/code_skin)\
**Post date:** [July 14, 2022, 8:18pm UTC](https://forum.inductiveautomation.com/t/parsing-a-json-string/61914/4 "2022-07-14T20:18:35Z")

</div>

Try to copy and paste this script to the Script Console.

```auto
test = [
	{"lpn":"00000709193070470712","location":"1 1 2 1 1 5 1 ","sku":"01318","lot_number":"220528","qc_status":"PASS","timestamp":1654020723000,"quantity":35,"sub_status":"DONE","status":"INDUCT","dest":"","reason_code":"Good Pallet","handstack":"N","row_locked":0}]
print test[0]['lpn']

```

When I copied your script, my Script Console was yelling about your **“** and **”**  
I replaced with " and all is well.

---

<div class="post-metadata">

**Author:** ![Michael.Usry](https://avatars.discourse-cdn.com/v4/letter/m/7c8e57/32.png) [@Michael.Usry](https://forum.inductiveautomation.com/u/Michael.Usry)\
**Post date:** [July 14, 2022, 8:31pm UTC](https://forum.inductiveautomation.com/t/parsing-a-json-string/61914/5 "2022-07-14T20:31:39Z")

</div>

Well, it works there. Difference being I’m using this in an onClick event. Also l’m getting the data from a namedQuery. The output I showed is the return I display in a label from it.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [July 14, 2022, 9:09pm UTC](https://forum.inductiveautomation.com/t/parsing-a-json-string/61914/6 "2022-07-14T21:09:43Z")

</div>

I’m guessing the return from the query is a string. Try running the result through [system.util.jsonDecode()](https://docs.inductiveautomation.com/display/DOC81/system.util.jsonDecode) first to turn it into a Pyhton object.

---

<div class="post-metadata">

**Author:** ![Michael.Usry](https://avatars.discourse-cdn.com/v4/letter/m/7c8e57/32.png) [@Michael.Usry](https://forum.inductiveautomation.com/u/Michael.Usry)\
**Post date:** [July 14, 2022, 9:23pm UTC](https://forum.inductiveautomation.com/t/parsing-a-json-string/61914/7 "2022-07-14T21:23:45Z")

</div>

I get an error that it can’t be coerced to String. When I print a type of the variable it says it’s a List.

---

<div class="post-metadata">

**Author:** ![Michael.Usry](https://avatars.discourse-cdn.com/v4/letter/m/7c8e57/32.png) [@Michael.Usry](https://forum.inductiveautomation.com/u/Michael.Usry)\
**Post date:** [July 14, 2022, 9:53pm UTC](https://forum.inductiveautomation.com/t/parsing-a-json-string/61914/8 "2022-07-14T21:53:03Z")

</div>

I got it with system.dataset.toPyDataSet() so I could you the [0][‘lpn’] to get the info. Thanks everyone!
