Fast JSON encoder/decoder compatible with encoding/json for Go It's a fork from github.com/goccy/go-json
- go 1.26
- long/short mode (long optimized for big buffers, short for small buffers)
// long json.UnmarshalWithOption(src, dst, json.DecodeLongBodyMode()) json.MarshalWithOption(x, json.EncodeLongBodyMode()) // short json.UnmarshalWithOption(src, dst, json.DecodeShortBodyMode()) json.MarshalWithOption(x, json.EncodeShortBodyMode()) // by default: autodetect json.Unmarshal(src, dst) json.Marshal(x)
- time formatter
json.MarshalWithOption(v, json.EncodeTimeFormat("2006-01-02 15:04:05")) // all time.Time in "v" will be formatted with this json.UnmarshalWithOption(data, &v, json.DecodeTimeFormats("2006-01-02 15:04:05", "2006-01-02")) // all time.Time will be deserialized with format "2006-01-02 15:04:05", if fails => format "2006-01-02"
- MarshalString/UnmarshalString: same as MarshalWithOption/UnmarshalWithOption, but works with string instead of []byte
- Required mode: (if required fields is missing Unmarshal returns error)
Field is optional if
omitemptyor type is pointer. Otherwise it's required.json.UnmarshalWithOption(data, json.DecodeRequire())
- Assembler optimizations for arm64 and amd64
- minor optimizations
- Drop-in replacement of
encoding/json - Fast ( See Benchmark section )
- Flexible customization with options
- Coloring the encoded string
- Can propagate context.Context to
MarshalJSONorUnmarshalJSON - Can dynamically filter the fields of the structure type-safely
Replace import statement from encoding/json to github.com/asvedr/go-json
-import "encoding/json"
+import "github.com/asvedr/go-json"