diff --git a/json.lua b/json.lua index 711ef78..2956e16 100644 --- a/json.lua +++ b/json.lua @@ -108,7 +108,12 @@ local function encode_number(val) if val ~= val or val <= -math.huge or val >= math.huge then error("unexpected number value '" .. tostring(val) .. "'") end - return string.format("%.14g", val) + local intVal = math.tointeger(val) + if intVal == val then + return string.format("%d", intVal) + else + return string.format("%.14g", val) + end end