I'm trying to parse a json file with JSON.lua module.
I get a ID from json and use this ID to get another value in the json data, like this:
Code: Select all
local file = assert(io.open(config, "r"))
local json_text = file:read("*all")
file:close()
local Conf = json:decode(json_text)
Station = Conf.station
for k,v in pairs(Station) do
local IDStation = v
local IDXHeight = Conf.idx.height.v
local IDXSpeed = Conf.idx.speed.v
local NotifHeightV = Conf.notifications.height.v.value
[...]
How can I force lua to remplace v with the value of the v variable ?
To get this for example:
Code: Select all
local IDXHeight = Conf.idx.height.L800001020
local NotifHeightV = Conf.notifications.height.L800001020.value
Code: Select all
{
"station": [
"L800001020",
"W141001001"
],
"idx": {
"height": {
"L800001020": "218",
"W141001001": "215"
},
"speed": {
"L800001020": "217",
"W141001001": "216"
}
},
"notifications": {
"height": {
"W141001001": {
"test": "ge",
"value": "2",
"active": "true"
},
"L800001020": {
"test": "gt",
"value": "1",
"active": "true"
}
},
"speed": {
"W141001001": {
"test": "ge",
"value": "100",
"active": "true"
},
"L800001020": {
"test": "ge",
"value": "140",
"active": "true"
}
}
}
}