lua-cjson
lua-cjson copied to clipboard
"integer" JSON value become float in lua5.3
environment: lua5.3 and lua-cjson 2.1.0.10-1
json file: cfg.json
{
"server_ip": "192.168.1.100",
"server_port": 10000,
}
lua code:
local cjson = require("cjson.safe")
local cfg_file_path = './cfg.json'
local cfg_fd = io.open(cfg_file_path, 'r')
local cfg_contents = cfg_fd:read("*all")
local cfg_obj = cjson.decode(cfg_contents)
for key, value in pairs(cfg_obj) do
print(value)
end
the printout result: 192.168.1.100 10000.0
We have a similar problem using cjson to process an opentelemetry request after decoding and encodind.
Input: "timeUnixNano":1686041011364000000
Output: "timeUnixNano":1.686041011364e+18