it is always interesting to see some float point number related things.
I tried your code, but did not have any problem:
► _VERSION
"LuaRT 2.1.0"
► json = require "json"
► array = { 1.9, 2, 3, "Hello !", n }
► print(json.encode(array))
[1.8999999999999999,2,3,"Hello !"]
► test = json.decode(json.encode(array))
► for key, value in pairs(test) do
print(key, value)
end
1 1.9
2 2
3 3
4 Hello !
►
1.9 format as 1.8999999999999999 is kind of weird.
though if fact it really is this strange value.
> 1.8+0.1 == 1.9
false
> string.format('%1.60f', 1.8+0.1)
1.900000000000000133226762955018784850835800170898437500000000
> string.format('%1.60f', 1.9)
1.899999999999999911182158029987476766109466552734375000000000
see what happened in python:
>>> json.dumps(1.9)
'1.9'
>>> json.loads('1.9')
1.9
>>> format(json.loads('1.9'), '.40f')
'1.8999999999999999111821580299874767661095'
it still is 1.8999.... though by default it only show it as 1.9. human-friendly?