There is a Dictionary where some values are primitive boxed values (bool, int, decimal) and others are null and DBNull.Value. Is it possible to output serialized JSON with undefined keyword for the latter category of entries using JSON.NET?
I was trying to set NullValueHandling.Ignore but that removes null-ed property completely. An implementation of JsonConverter does not help as it is not used on null value.
To illustrate my question consider this object
var toSerialize = new Dictionary<string, object> =
{
{"key1": 1},
{"key2": true},
{"key3": DBNull.Value},
{"key4": null}
};
The result should be as
{
"key1": 1,
"key2": true,
"key3": undefined,
"key4": undefined
}
and not as
{
"key1": 1,
"key2": true,
"key3": null,
"key4": null
}
the indentation is not important. Thanks.
undefineddoes not exist in json. Only numbers, floats, strings, booleans, objects, arrays and null are valid json entries{}is considered asundefined.{}does not considered asundefinedby the test liketypeof va === "undefined"nullcount for that test?undefinedis not legal json, you will not be able to serialize to that in C#. You will have to find some other way of reaching your goal.