Skip to content
master
Switch branches/tags
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Json

Standard Go "encoding/json" package with a few enhancements.

Last updated : 22nd of June 2018

Removed features

  • TextUnmarshaler and TextMarshaler

New features

  • fewer allocations - benchmarks are present
  • encode state is the options carrier, instead of passing around options as parameter
  • optional sort map keys on serializing
  • encoding and decoding of Null typed structs (NullString, NullBool, etc.) - see TestNewNull in encode_test.go for the Marshalers and TestNewDecodeNull in decode_test.go
  • minimal reflect, extracted from reflect package
  • fast number scanner in strconv - numbers are already validated on decoding, so there is no need to validate (to be described)
  • minimal strconv package included - instead of working with strings we're working with []byte (to be described)
  • fixed omitempty struct bug :
    type (
		// note that all fields are omit empty
		EmptyStruct struct {
			Id   int64  `json:"id,omitempty"`
			Name string `json:"name,omitempty"`
			Bool bool   `json:"bool,omitempty"`
		}

		Test struct {
			Id       uint64      `json:"id"`
			MyStruct EmptyStruct `json:"myStruct,omitempty"` // and this one is marked as omit empty
		}
	)
	// the result should not contain "myStruct":{} - but it does
	tester := &Test{Id: 3}
	result, err := json.Marshal(tester)

The result is {"id":3} not {"id":3,"myStruct":{}}.

Possible Known Issues

  • Working with maps : when using Marshal with maps, developers should make sure that the map doesn't change. For allocation reasons, I have removed the code that was copying map's key and value before reading it.

About

Standard "encoding/json" package arranged for my needs

Topics

Resources

Releases

No releases published

Packages

No packages published

Languages