Page MenuHomeSoftware Heritage

do not return null-valued fields in JSON answers
Closed, MigratedEdits Locked

Description

In several cases the Web API returns null-values fields in its JSON answers.
That should be avoided because doing so forces web clients to do extra gymnastics to distinguish the "null" case vs the empty dict/list cases or the absence of a given metadata key. It also wastes bandwidth, but that's a minor point.

I've found at least the following occurrences of this happening, but there might be more:

We should consistently either return empty dict/lists instead of returning null (depending on the expected type), or consistently removing keys that point to null values from the return dictionaries.

Event Timeline

zack moved this task from Restricted Project Column to Restricted Project Column on the Restricted Project board.
zack renamed this task from do not return useless null-valued fields in JSON answers to do not return null-valued fields in JSON answers.Jan 17 2017, 9:20 AM
zack lowered the priority of this task from High to Normal.

Upon reflection, I propose:

  • for "plural" data types (lists and dictionaries), we should always return their empty counterparts ([], {}) instead of null
  • for "singular" data types (strings, integers, etc), we should remove the corresponding keys from the JSON dictionary instead of returning null
    • assuming this applies right now only to stuff like "lister" and "project", not returning them is the right thing to do anyhow, as that part of our dataflow isn't fully reflected in the content of our database anyhow