I’m designing my first API for a web app based on a MongoDB datastore.
I return json responses and I don’t know how to decide, which is better:
Keeping a consistent response scheme with empty fields or null.
Or returning only non-empty values.
That imply for examples, when removing values from an array on my Mongo, I need to check if the array is empty, and if so, $unset it.
I prefer to avoid nulls for relational schemas and application code; I’d recommend the same for NoSQL.
“null” means “I don’t know” to me.
An empty object says “You asked for this, but nothing was there.” I think it’s more explicit and correct.