go-ipfs-cmds
go-ipfs-cmds copied to clipboard
Sanitize null arrays to []
Currently, depending on circumstances arrays can be either Marshalled to JSON as null or []. It would be best if we send just one format, possibly the [].
As a consumer of the HTTP API, I would greatly prefer to receive an empty array compared to null, since you don't really have to have any special logic, you just can treat it as an array while forEach
with null would fail for example.
I agree that this would be preferable, but unfortunately I don't really know how to do that without either (a) initializing all nil slices to empty slices or (b) using custom types for all slices with MarshalJSON
functions that encode nil values to '[]'. Both of these can not be fixed in this library, but on the code that determines which values to be sent (i.e. go-ipfs).
I'll try to find all instances in this package, though.
@keks I've filed a feature request to always encode slices/maps to []
and {}
with refmt (a marshaling library we're planning on using for IPLD stuff): https://github.com/polydawn/refmt/issues/25
If that works out, we can just replace the json library with that one.