Embedded Lua ParseJson function converting integers to float

I inadvertently posted to the old Google groups before I saw the notification of the move here.

I noticed that the embedded Lua ParseJson function converts incoming json integers to floats when creating the output Lua table.

I am using the osimis/orthanc image with Orthanc 1.11.3.

I can get around the problem by explicitly casting the value after conversion to a Lua table with the math.floor() function.

As an aside, I am still in the process of converting my embedded Lua code base to Python in order to use the python plugin. In the current mixed Lua/Python environment, I pass values back to my Lua codes using json objects created in the newer replacement Python codes.

I ran into the ParseJson integer to float conversion issue just recently when I finally needed to send an integer back to the Lua script from the python side.

John.

Hi John

First of all, sorry for the late answer.

I have not been able to reproduce the issue. Trying to run this code printed ‘4’ which is what I expect:

local js = '{"a": 4}'
local j = ParseJson(js)
print(j['a'])

However, while stepping into the code, I realized that 4 was first checked for isDouble() and then for isInt() which might explain your issue since 4 is both a double and an int in jsoncpp.

Hence this commit that might help you.

Best regards,

Alain.

1 Like