Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sanitize null arrays to [] #75

Open
Kubuxu opened this issue Mar 16, 2018 · 3 comments
Open

Sanitize null arrays to [] #75

Kubuxu opened this issue Mar 16, 2018 · 3 comments

Comments

@Kubuxu
Copy link
Member

Kubuxu commented Mar 16, 2018

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 [].

@victorb
Copy link
Member

victorb commented Mar 16, 2018

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.

@keks
Copy link
Contributor

keks commented Apr 10, 2018

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.

@Stebalien
Copy link
Member

@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): polydawn/refmt#25

If that works out, we can just replace the json library with that one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants