1 local jsonencode
= require("json.encode")
7 local tostring = tostring
9 local table_concat
= table.concat
11 local strings
= require("json.encode.strings")
13 module("json.encode.object")
15 function encode(tab
, options
)
16 local encodeValue
= jsonencode
.encodeValue
17 local encodeString
= strings
.encode
20 for i
, v
in pairs(tab
) do
22 assert(ti
== 'string' or ti
== 'number' or ti
== 'boolean', "Invalid object index type: " .. ti
)
23 i
= encodeString(tostring(i
), options
)
25 retVal
[#retVal
+ 1] = i
.. ':' .. encodeValue(v
, options
)
27 return '{' .. table_concat(retVal
, ',') .. '}'