Skip to content

asvedr/go-json

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1,104 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-json

Fast JSON encoder/decoder compatible with encoding/json for Go It's a fork from github.com/goccy/go-json

Defference 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 omitempty or type is pointer. Otherwise it's required.
    json.UnmarshalWithOption(data, json.DecodeRequire())
  • Assembler optimizations for arm64 and amd64
  • minor optimizations

Features

  • Drop-in replacement of encoding/json
  • Fast ( See Benchmark section )
  • Flexible customization with options
  • Coloring the encoded string
  • Can propagate context.Context to MarshalJSON or UnmarshalJSON
  • Can dynamically filter the fields of the structure type-safely

How to use

Replace import statement from encoding/json to github.com/asvedr/go-json

-import "encoding/json"
+import "github.com/asvedr/go-json"

About

Fast JSON encoder/decoder compatible with encoding/json for Go

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Packages

 
 
 

Contributors

Languages

  • Go 92.6%
  • Go Template 7.2%
  • Other 0.2%