10 ms·
When defining payloads for updates, it is really useful to be able to distinguish something like {"name": null, "age": 25} // Set name to null, and age to 2
by yen223 3y ago
When defining payloads for updates, it is really useful to be able to distinguish something like
{"name": null, "age": 25} // Set name to null, and age to 25
from
{"age": 25} // Only set age to 25, leave name alone
In the former, "name" has value `null`; in the latter, the "name" field has value `undefined`
Most strongly-typed mainstream backend languages don't make this distinction between "a field having value null" and "a field not being present", and this results in those languages parsing both payloads as the same. This makes API design much harder than it needs to be.
- giaour 3y agoThis is really only true if your serialization format allows you to supply an explicit `null`, omit arbitrary properties, and has no representation corresponding to `undefined`. In practice, only JSON (and serialization formats explicitly designed to be isomorphic to JSON) exhibit these characteristics.