08.08.2022, 08:34
Hi !
I am working on LM app development and below is the index.lp code.
From the commandline I can use the endpoint like this , with a request body. It returns the result like this : {"results":[{"alias":"6\/6\/1","value":true}]}
Is there a way to remove the backslash in from the result json string ?
Thank you !
http://id:pass@LM local IP/apps/data/logic-machine/index.lp
{
"commands":[
{
"alias":"6/6/1",
"value":true
}
]
}
I am working on LM app development and below is the index.lp code.
From the commandline I can use the endpoint like this , with a request body. It returns the result like this : {"results":[{"alias":"6\/6\/1","value":true}]}
Is there a way to remove the backslash in from the result json string ?
Thank you !
http://id:pass@LM local IP/apps/data/logic-machine/index.lp
{
"commands":[
{
"alias":"6/6/1",
"value":true
}
]
}
Code:
<?
require('json')
require('apps')
params = ngx.req.get_body_data()
params = json.pdecode(params)
require('custom.utils')
results = {}
if params ~= nil then
for index, command in ipairs(params.commands) do
if type(command.alias) ~= nil or type(command.value) ~= nil then
res = grp.write(command.alias, command.value) or false
table.insert(results, {value = res, alias = command.alias})
end
end
results = {
results = results
}
write(json.encode(results))
end
?>