Lua pull from json  [Solved]

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
doger31
Posts: 2
Joined: Wednesday 23 October 2019 18:05
Target OS: -
Domoticz version:
Contact:

Lua pull from json

Post by doger31 »

I am looking for help with the json api answer:

{ "Global Quote": { "01. symbol": "GLG", "02. open": "0.4780", "03. high": "0.4800", "04. low": "0.4650", "05. price": "0.4760", "06. volume": "14183", "07. latest trading day": "2019-10-23", "08. previous close": "0.4754", "09. change": "0.0006", "10. change percent": "0.1262%" } }

I would like to pull the variable of "05. price".

when I do json.decode it tells me that this is table not string

when I do print(item["Global Quote"][5]) i got (a nil value)

when i do: for x,y in pairs(item) do print(y)

i got:

"Global Quote": { "01. symbol": "GLG", "02. open": "0.4780", "03. high": "0.4800", "04. low": "0.4650", "05. price": "0.4760", "06. volume": "14183", "07. latest trading day": "2019-10-23", "08. previous close": "0.4754", "09. change": "0.0006", "10. change percent": "0.1262%"
doger31
Posts: 2
Joined: Wednesday 23 October 2019 18:05
Target OS: -
Domoticz version:
Contact:

Re: Lua pull from json  [Solved]

Post by doger31 »

I managed to resolve my issue.
After i added:
local json = domoticz.utils.fromJSON(item.data)

I am able to index through the table. (json["Global Quote"]["05. price"])
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest