web services - Presenting missing values as null or not at all in JSON -
i building web service api, using json data language. designing structure of data returned service, having trouble deciding how deal missing values.
consider example: have product in web store price yet unknown, maybe because product has not yet been released. include price: null
(as shown below) or omit price
property on item?
{ name: 'osx 10.6.10', brand: 'apple', price: null }
my main concern making api easy consume possible. explicit null value makes clear price
can expected on product, @ other hand seems wasted bytes. there whole bunch of properties irrelevant particular product, while relevant other products – should show these explicitly null
well?
{ name: 'osx 10.6.10', price: 29.95, color: null, size: null }
are there "best practices" on web service design, favoring explicit or implicit null values? de-facto standard? or depend entirely on use case?
fwiw, personal opinion:
do include
price: null
(as shown below) or omit price property on item?
i set values of "standard" fields null
. although json used javascript , there, missing properties can handled ones set null, must not case other languages (e.g. java). having test first whether field present seems inconvenient. setting values null
having fields present more consistent.
there whole bunch of properties irrelevant particular product, while relevant other products – should show these explicitly
null
well?
i include fields relevant product (e.g. not pages
cd). it's client's task deal these "optional" fields properly. if have no value field relavant product, set null
too.
as said, important thing consistent , specify fields can expected. can reduce data size using gzip compression.
Comments
Post a Comment