lua-cjson icon indicating copy to clipboard operation
lua-cjson copied to clipboard

"integer" JSON value become float in lua5.3

Open dong-king opened this issue 1 year ago • 1 comments

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

dong-king avatar Apr 04 '23 14:04 dong-king

We have a similar problem using cjson to process an opentelemetry request after decoding and encodind.

Input: "timeUnixNano":1686041011364000000 Output: "timeUnixNano":1.686041011364e+18

LitschiW avatar Jun 06 '23 09:06 LitschiW