Link to blog post from today:
As somebody who lives and breathes JSON every day all day, this is really interesting to me. I don’t personally care about things like rejecting invalid UTF-8 characters, but I can see a use case for the new jsontext package:
The
jsontextpackage provides functionality for interacting with JSON at a syntactic level and derives its name from RFC 8259, section 2 where the grammar for JSON data is literally calledJSON-text. Since it only interacts with JSON at a syntactic level, it does not depend on Go reflection.
Out of the box, unmarshal performance is greatly improved:
The
Marshalperformance ofv2is roughly at parity withv1. Sometimes it is slightly faster, but other times it is slightly slower. TheUnmarshalperformance ofv2is significantly faster thanv1, with benchmarks demonstrating improvements of up to 10x.
And if you implement a new interface you can enable streaming:
In order to obtain greater performance gains, existing implementations of
MarshalerandUnmarshalershould migrate to also implementMarshalerToandUnmarshalerFrom, so that they can benefit from processing JSON in a purely streaming manner. For example, recursive parsing of OpenAPI specifications inUnmarshalJSONmethods significantly hurt performance in a particular service of Kubernetes (see kubernetes/kube-openapi#315), while switching toUnmarshalJSONFromimproved performance by orders of magnitude.
I’m interested in checking this out and wish it came a bit sooner. I’m about to launch into a project where I’m building the go library for an existing mongo-like DB API and this sounds like it would be a good fit for my project. What do you all think?