json empty brace {}

Hi,

I want to create this json:

{"id":1,"type":0,"data":["messages::create",{"text":"Message from client"},{}]}

i created json like this:

 local t = { ["type"] = 0, ["data"] ={"messages::create",{["text"]="Message from client"},{}}, ["id"]=1 } 

but lua converts {} to [] , so how can i get {} in the json?

The easiest way is to start with the JSON, decode it and see what tables are produced.

local j = "{\"id\":1,\"type\":0,\"data\":[\"messages::create\",{\"text\":\"Message from client\"},{}]}" local t = require("json").decode(j) local function dump(t) for k,v in pairs(t) do print(type(v),k,v) end print(" ") end dump(t) dump(t.data) print(t.data[1]) for i=2, #t.data do dump(t.data[i]) end

I did not understand what you mean.

I needed the json to send as a request to node.js server and it has a fixed structure ,

but it seems that node.js server allowed my json in first post

The easiest way is to start with the JSON, decode it and see what tables are produced.

local j = "{\"id\":1,\"type\":0,\"data\":[\"messages::create\",{\"text\":\"Message from client\"},{}]}" local t = require("json").decode(j) local function dump(t) for k,v in pairs(t) do print(type(v),k,v) end print(" ") end dump(t) dump(t.data) print(t.data[1]) for i=2, #t.data do dump(t.data[i]) end

I did not understand what you mean.

I needed the json to send as a request to node.js server and it has a fixed structure ,

but it seems that node.js server allowed my json in first post