openresty / lua-cjson

Lua CJSON is a fast JSON encoding/parsing module for Lua
http://www.kyne.com.au/~mark/software/lua-cjson.php
MIT License
432 stars 118 forks source link

"integer" JSON value become float in lua5.3 #91

Open dong-king opened 1 year ago

dong-king commented 1 year ago

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

LitschiW commented 1 year ago

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

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