in kong/kong/api/api_helpers.lua [176:218]
fdata_to_jsonable = function(fdata, is_array)
local out = {}
local iter = is_array == "yes" and ipairs or pairs
for k, v in iter(fdata) do
if is_array == "maybe" and type(k) ~= "number" then
is_array = "no"
end
if k == "schema" then
out[k] = schema_to_jsonable(v)
elseif type(v) == "table" then
if k == "fields" and fdata.type == "record" then
out[k] = fields_to_jsonable(v)
elseif k == "default" and fdata.type == "array" then
out[k] = fdata_to_jsonable(v, "yes")
else
out[k] = fdata_to_jsonable(v, "maybe")
end
elseif type(v) == "number" then
if v ~= v then
out[k] = "nan"
elseif v == math.huge then
out[k] = "inf"
elseif v == -math.huge then
out[k] = "-inf"
else
out[k] = v
end
elseif type(v) ~= "function" then
out[k] = v
end
end
if is_array == "yes" or is_array == "maybe" then
setmetatable(out, cjson.array_mt)
end
return out
end