My Golang JSON Evaluation
Which lib should you use? Native, jsoniter, easyjson or go-json? And why?
JSON (Javascript Object Notation), a prevailing data exchange format, is widely used in various platforms and languages. Golang, of course, will never miss the support for JSON. And with its own standard library, such as those interfaces like the REST API from the API Service in Kubernetes, it can easily process JSON.
Although Go’s library works great, we can still seek those open-source JSON libs in Github to maximize our efficiency. Then the features, performance, applicability of these libs are what we should put into consideration.
And here comes my “evaluation report.”
JSON In Go
There are two steps when manipulating JSON with Go’s self-contained encode/json
package.
- Define the mapping. That is, mapping the field from struct to the corresponding JSON.
- Serialization, achieving the conversion between JSON string and struct with
Marshal
orUnmarshal
methods.
An example is as follows.