2 ms·
In JSON/REST API bindings, where a deserializer maps JSON to language-native object/struct type, I'll often need to know the difference between: {} and
by kelnos 1y ago
In JSON/REST API bindings, where a deserializer maps JSON to language-native object/struct type, I'll often need to know the difference between:
{}
and
{ "foo": null }
and
{ "foo": 42 }
So I'll represent that (in e.g. Rust) as:
struct Whatever {
foo: Option<Option<u32>>,
}
None means not present, Some(None) means present but null, and Some(Some(42)) means present with a value.
I'll often use this in PATCH endpoints, where not-present means to leave the current value alone, null means to unset it, and a value means to set to that value.