https://github.com/badu/json
Standard "encoding/json" package arranged for my needs
https://github.com/badu/json
golang json
Last synced: 3 months ago
JSON representation
Standard "encoding/json" package arranged for my needs
- Host: GitHub
- URL: https://github.com/badu/json
- Owner: badu
- Created: 2018-05-07T07:44:24.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2018-11-13T04:24:21.000Z (over 7 years ago)
- Last Synced: 2025-01-19T09:31:56.551Z (over 1 year ago)
- Topics: golang, json
- Language: Go
- Homepage:
- Size: 352 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 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 :
```go
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.