NSJSONReadingOptions to ignore nulls

Number:rdar://36304964 Date Originated:January 4 2018, 3:53 PM
Status:Open Resolved:
Product:iOS + SDK Product Version:11.2
Classification:Suggestion Reproducible:

An NSJSONReadingOptions to ignore nulls will be very useful.

In most cases nulls in JSON are unwanted. They are not just useless. They actually make populating app data much harder and less safe: Say an attribute "title" is of type NSString. If the corresponding value in JSON may be null sometimes, I have to check whether it is [NSNull null] before assigning to title, otherwise it crashes.

In reality, every field in JSON may be null for whatever reasons, and data from severs are usually out of app developers' control. So it means we have check for NSNull when assigning every single attribute of app data from JSON. It is really tedious.

Yes, I can preprocess JSON dictionaries to filter out nulls before population app data. It will simply the code but will incur performance cost.

If there is a NSJSONReadingIgnoreNulls, NSJSONSerialization can filter out nulls when convening JSON data into Foundation objects, without additional performance cost since it already detects nulls anyway. It will make out lives so much easier.

Since it is an option nulls can still be maintained in case they are needed.


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!