Creating responses in JSON format

In case when Gate HTTP module works as Listener, there is a possibility that its response has to be in JSON type.


Assuming that the sent response looks like:


There is a need to create the following script on Gate HTTP module:

local resp = {body=, {sensor_2_inside={value=21.8}}}}

Gate_HTTP->Listener_JSON->SetResponseBody(resp)
Gate_HTTP->Listener_JSON->SendResponse()


which has to be assigned to OnRequest event in HttpListener virtual object:


In case when the returned parameter contains in its name the "." character:


The script assigned to OnRequest event in HttpListener virtual object should look like follows:

local resp = {}
resp.body = {}
resp.body[1] = {}
resp.body[1]["sensor.1.outside"] = {}
resp.body[1]["sensor.1.outside"]["value"] = 17.2
resp.body[2] = {}
resp.body[2]["sensor.2.inside"] = {}
resp.body[2]["sensor.2.inside"]["value"] = 21.8

Gate_HTTP->Listener_JSON->SetResponseBody(resp)
Gate_HTTP->Listener_JSON->SendResponse()