I am creating a web services API using JSON as the data language. By creating a structure for the data returned from the service, I am having some problems resolving problems with missing values.
Consider this example: I have a product in my online store whose price is not yet known, possibly because the product has not yet been released. Include price: null (as shown below) or just omit the price property in this element?
{ name: 'OSX 10.6.10', brand: 'Apple', price: null }
My main concern is to make the API as easy to use as possible. The explicit empty value makes it clear that the price can be expected on the product, but on the other hand, it looks like wasted bytes. There may be a whole bunch of properties that are completely unrelated to this particular product, and also apply to other products - should I show them as explicitly null ?
{ name: 'OSX 10.6.10', price: 29.95, color: null, size: null }
Are there any “best practices” in web service design that support explicit or implicit null values? Any de facto standard? Or does it completely depend on the use case?
source share