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
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.
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:
The “string” tag no longer applies recursively (for consistency with other tags).
The “format” tag is removed (we hope to bring this back with better syntax using something like https://go.dev/issue/74472).
Small adjustments to encoding/json/jsontext helper functions (e.g., jsontext.Token.Int and friends can now return an error).
Probably a few other minor changes I’m forgetting at the moment.
thiht | 11 hours ago
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
xilef | 13 hours ago
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.
fanf | 17 hours ago
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.
prattmic | 15 hours ago
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:
payne | 9 minutes ago
v1 being internally reimplemented with v2 is incredibly nice and something I didn't know they did before reading this.