sitemule / noxDB

Not only XML. SQL,JSON and XML made easy for IBM i
MIT License
41 stars 20 forks source link

Parsing null from a string leads to empty string when printing JSON #78

Closed SteffenHaugeKtp closed 1 year ago

SteffenHaugeKtp commented 1 year ago

Code to reproduce:

dcl-s p1 pointer;
dcl-s p2 pointer;
dcl-s jsonText varchar(1000);

p1 = json_newObject();
json_setNull(p1:'a');
jsonText = json_asJsonText(p1);// {"a":null}
json_close(p1);

p2 = json_parseString('{"a":null}');
jsonText = json_asJsonText(p2);// {"a":""}
json_close(p2);

This seems to happen due to isLiteral not getting set for null values https://github.com/sitemule/noxDB/blob/53bc7c6a9eead54e9dc1f70002f2a98655fe4cbd/src/jsonparser.c#L255-L257

And when it gets printed https://github.com/sitemule/noxDB/blob/53bc7c6a9eead54e9dc1f70002f2a98655fe4cbd/src/serializer.c#L171-L175