1

We have a resource whose structure is like this:

{  
   "id":100,
   "title":"SOME_TITLE",
   "logo":[  
      {  
         "uri":"SOME_URL",
         "mimeType":"jpg",
         "type":null,
         "priority":0,
         "size":null
      }
   ]
}

Some of the resources do not have "logo" and there are two ways to represent this situation

1st.

{  
   "id":100,
   "title":"SOME_TITLE",
   "logo": null
}

2nd.

{  
   "id":100,
   "title":"SOME_TITLE",
}

In any case, our clients are handling the case, so the question focuses more on the design. Which approach is better? nulling the missing field or removing it completely from the response?

Cagatay Gurturk
  • 7,186
  • 3
  • 34
  • 44

1 Answers1

0

I prefer Removing it completely for multiple reason:

  • If you remove it, you have to send les information on your response, and when this rest API is used by mobile devices you expend less data.
  • If you consume this rest API on Java, null values is pain in the ass
  • It is easer see if there is the information that you want to receive
Jc Miñarro
  • 1,391
  • 10
  • 18
  • As the above said, it's software design issue, and I'm agree with Jc Minarro – ItayB Sep 22 '15 at 11:08
  • Disagree because of the reasons mentioned here: https://stackoverflow.com/questions/21188145/is-it-worth-to-exclude-null-fields-from-a-json-server-response-in-a-web-applicat – Dennis Sep 20 '22 at 08:46