json with dash '-' in object name

Easy to use, 100% Lua-based event scripting framework.
Post Reply
hestia
Posts: 13
Joined: Tuesday 26 December 2017 0:06
Target OS: Raspberry Pi
Domoticz version: 4.9700
Location: Paris
Contact:

json with dash '-' in object name

Post by hestia » Monday 05 November 2018 0:30

how to use a object from a json when the name of this object contains a dash '-'
example:
triggerObject.json.currently.time) => OK
triggerObject.json.flags.nearest-station) => KO :-(

to use https://darksky.net/dev/docs#overview

gerardvs
Posts: 136
Joined: Sunday 04 January 2015 1:01
Target OS: Raspberry Pi
Domoticz version: latest-1
Location: /dev/null
Contact:

Re: json with dash '-' in object name

Post by gerardvs » Monday 05 November 2018 11:08

Try ["nearest-station"]

hestia
Posts: 13
Joined: Tuesday 26 December 2017 0:06
Target OS: Raspberry Pi
Domoticz version: 4.9700
Location: Paris
Contact:

Re: json with dash '-' in object name

Post by hestia » Friday 09 November 2018 20:37

Thanks gerardvs
but it doesn't work :-(
=> lua:171: <name> expected near '['

elmortero
Posts: 238
Joined: Sunday 29 November 2015 21:46
Target OS: Raspberry Pi
Domoticz version: 3.9639
Location: Spain
Contact:

Re: json with dash '-' in object name

Post by elmortero » Friday 09 November 2018 21:01

triggerObject.json.flags["nearest-station"] (no . before [ )

hestia
Posts: 13
Joined: Tuesday 26 December 2017 0:06
Target OS: Raspberry Pi
Domoticz version: 4.9700
Location: Paris
Contact:

Re: json with dash '-' in object name

Post by hestia » Saturday 10 November 2018 23:26

Thanks elmortero

print('nearest-station: '.. triggerObject.json.flags["nearest-station"]) => OK

bravo!

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests