0

I am parsing some json data that has a date element, and sometimes its value can be null. My application needs to be able to handle nulls, therefore I have to set the date value to a default value, so I am not sure if there is a convention / rule that I should be following? Any help is appreciated!

  • When the field is null, it should be `:null` or the field should be omitted in the json. Depending on the language you are using, a `Nullable` should be a valid datatype (the syntax depending on the language) – Pete Garafano Aug 12 '14 at 22:44
  • The data that I am parsing is from a third party service and I am using the date to historically calculate some values. So for example if I am calculating average of deaths over the years, one value could potentially change my outcome.. therefore I cannot leave it null – user3920151 Aug 12 '14 at 22:54
  • If, per your example, I have 10 data points, 9 have a year, 1 does not. I want to take the average of 3 consecutive years, how do I know to which set of 3 years the data point with a null date belongs? The value cannot be used in a statistical analysis in this way. In this case, you might be able to deduce the year since it would be the only one missing from the set, but if you're missing 2 or more you cannot know. They should (statistically speaking) be removed from the analysis for the example given. – Pete Garafano Aug 13 '14 at 13:40

1 Answers1

0

If you get null where you expect a date, that means whoever created the data intentionally gave you a null value. You shouldn't even think about using some default date. You should store the information that no date was provided. A null value is even stronger than a missing key/value pair in a dictionary.

gnasher729
  • 51,477
  • 5
  • 75
  • 98
  • The data I am parsing is from a third party service and it should not be empty, but if I am getting empty value then my application should be coded to handle it and I since the other data is used for historical calculations, I would not like to leave it as null. – user3920151 Aug 12 '14 at 22:56