Consider the following scenario:
var s1 = "{\"hello\":\"world\", \"test\":\"somevalue\"}";
var s2 = "{\"hello\":\"world\", \"test\":null}";
var j1 = JObject.Parse(s1);
var j2 = JObject.Parse(s2);
j1.Merge(j2, new JsonMergeSettings { MergeArrayHandling = MergeArrayHandling.Union, MergeNullValueHandling = MergeNullValueHandling.Merge });
var jf = JsonConvert.SerializeObject(j1, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });
The result jfis{"hello":"world", "test":null}
How can I call the library for the merge result:
{"hello":"world"}
Is this the case when I would have to recursively traverse the resulting object and delete the null value'd properties manually? Or is there a magic wand that says: "Just clear these zero values when serializing"
I know about JsonProperty -> NullValueHandling, but these are dynamic objects that I work with, so the model is unknown.
source
share