Search code examples
cjsonserialization

Invalid json float conversion depending on server


I wrote a C library that returns some JSON strings using the json-c library. This library is used by a Tomcat Java server (through JNI), and the JSON is passed to a client browser and parsed by a JavaScript there. On one server, everything works fine. We replicate that server onto another machine, and there there is some garbage in the JSON. For instance:

{ "Data": [ -5.3014e+05, -5.3022e+05.0, -5.3028e+05, -5.3023e+05, -5.3031e+05 ], "Name": "MonitorCurrent @ circuit_17", "Desc": "ADC averaged value 24bit" }

This ...e+05.0 breaks the parsing. I'm stumped by what could be the cause. The only thing I can think of is some multithreading problem, but all the statics are thread-local, and anyway the only error I've found so far is this .0 added to some exponents.

I used the following serialization:

json_c_set_serialization_double_format("%.5g", JSON_C_OPTION_GLOBAL);

EDIT: I have the same error if I call the lib directly from C, so the problem has nothing to do with Java/Javascript/Tomcat/Multithreading/.... It's only between C, json-c and the machine. The working one is Centos 8.5, the other is openSUSE Leap.


Solution

  • It's a bug in libjson-c 0.13. If I link with 0.15 or 0.17, there's no problem.