Closed togamid closed 3 months ago
In what situation is it ok for what should be a string to be null instead? ISTM that that is more an indication that something has gone wrong and if we're checking for NULL then it should be as assert(s!=NULL)
to trigger an intentional crash.
In my case I get a relatively large struct with multiple fields that can be either a string if they are applicable or NULL if they aren't.
IMO adding this to the json-c API would encourage sloppy coding that would lead to much less reliability since accidentally passing NULL to these function would silently appear to work until the lack of a string object where there was supposed to be one caused problems later. I'm closing this without any changes to json-c.
Currently, every time a nullable string field is added to a json_object, the user has to first test if the field is null and call json_object_new_string() or json_object_new_null() based on that.
Checking for NULL in json_object_new_string() and json_object_new_string_len() is a small change that would make the calling code cleaner and json-c more reliable.