This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

strange backslash when json.write
#1
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
        }
    ]
}
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
?>
Reply


Messages In This Thread
strange backslash when json.write - by Hadeel - 08.08.2022, 08:34

Forum Jump: