You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
golang's stdlib encoding/json library currently marshals empty arrays as null rather than [], causing downstream JSON parsing to often fail.
Practically, many JSON parsers reject raw arrays that are not wrapped in some { blah: array } object structure. I think that is wasteful, but if encoding/json were to behave more predictably, it could have at least reported an error when Marshal() is passed an array instead of a struct / hashmap. Instead we get null for empty arrays, which is not a value anyone but old LISPers from the 50's would expect.
Perhaps we can bring this improvement back to encoding/json, without breaking backwards compatibility, by introducing new methods and deprecating old methods.
The text was updated successfully, but these errors were encountered:
golang's stdlib
encoding/json
library currently marshals empty arrays asnull
rather than[]
, causing downstream JSON parsing to often fail.Practically, many JSON parsers reject raw arrays that are not wrapped in some
{ blah: array }
object structure. I think that is wasteful, but if encoding/json were to behave more predictably, it could have at least reported an error whenMarshal()
is passed an array instead of a struct / hashmap. Instead we getnull
for empty arrays, which is not a value anyone but old LISPers from the 50's would expect.As a workaround, some Go users are substituting https://github.com/helloeave/json
Perhaps we can bring this improvement back to encoding/json, without breaking backwards compatibility, by introducing new methods and deprecating old methods.
The text was updated successfully, but these errors were encountered: