Reputation: 5081
I'm working on an api that provides JSON responses. One of the items is typically a bool, but in some cases, it is "n/a".
The two options I'm considering are:
The first option is "truthy" though and if someone implemented the API poorly, it could result in a false positive (although it's a little more clear to a human reader). The second result is "falsey" but doesn't really provide the same clarity to a human reader of the result.
Upvotes: 0
Views: 169
Reputation: 3141
I would go with null
which means that property does not have any value, regardless if it's boolean, string etc. It will keep data type consistent, otherwise you would have to mix Boolean
with String
which is probably bad idea and will definitely not make life of API consumers easier. Or keep the value string and pass Boolean
as a String
, which also sounds like a workaround.
N/A
seems to be more like a representation of null
value on the consumer side. And by the way different consumers can represent it in different way. Or it could be not the same for different locales.
Upvotes: 1