A new Go API for JSON
22 points by binjip978
22 points by binjip978
I really love that Go figured a way to version the stdlib without making breaking changes and in a way that’s natural with Go modules major versions. Just having /v2 paths feels really simple and elegant to me
Anyway to stay on topic, my favorite change about json/v2 is definitely how it makes it possible (and even defaults) to serialize nil slices / maps as empty JSON arrays / objects instead of null. This was long overdue and makes it much easier when working with Typescript on the consumer end of an API
This has been in the works for over a year so there have been articles about it previously (25 comments), previously, previously; from a quick skim of this article I can’t see a summary of what has changed since last year.
There aren’t any major changes from the original GOEXPERIMENT.
This post is actually an updated version of last year’s experiment post at https://go.dev/blog/jsonv2-exp. From what’s described there literally the only update I had to make from that post is that the “inline” struct tag was renamed to “embed”.
Other minor changes to functionality from the original GOEXPERIMENT:
I recently migrated a reasonably JSON-heavy set of services to the V2 and it went very smoothly. The one thing that caught us was the lack of newlines in generated JSON, but that forced us to inspect our tests again so not a bad thing.