Parsing a JSON string

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.

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

print variable[0][“lpn”]

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

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

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.

1 Like

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.

I’m guessing the return from the query is a string. Try running the result through system.util.jsonDecode() first to turn it into a Pyhton object.

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.

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