Open OSalama opened 2 months ago
It seems this requirement might not be very common, could you provide more details about how you're using yyjson to output JSON?
If you're building JSON using yyjson_mut_val
, I suggest adding a single line of code after you finish creating an object:
yyjson_mut_val *obj = ...
if (!yyjson_mut_obj_size(obj)) yyjson_mut_set_null(obj);
Is your feature request related to a problem? Please describe. I'm loading data output by yyjson into Spark/Hive tables, and the fact that empty objects are output as
{}
instead ofnull
is causing a lot of issues, because Spark is not able to infer any meaningful schema and ends up dropping the empty object fields.Describe the solution you'd like Output empty objects as
null
instead of{}
. I'd be happy to have to use a flag to achieve this.Describe alternatives you've considered The only alternatives I can see would be outside the scope of yyjson, eg:
{}
tonull
- this feels like it would be really slow and defeat a lot of the point of using yyjson.{}
becomes{optional_field_1: null, optional_field_2:null, ...}
- this feels "wrong", since there is a distinction between a null object and an object with keys and null values.Additional context N/A