https://github.com/infiniteloopcloud/json
Copy of Go's built-in json with IsZero support
https://github.com/infiniteloopcloud/json
golang golang-json golang-library golang-package json
Last synced: 2 months ago
JSON representation
Copy of Go's built-in json with IsZero support
- Host: GitHub
- URL: https://github.com/infiniteloopcloud/json
- Owner: infiniteloopcloud
- License: mit
- Created: 2023-02-22T13:29:06.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-02-26T18:32:40.000Z (over 3 years ago)
- Last Synced: 2026-04-25T10:36:53.099Z (2 months ago)
- Topics: golang, golang-json, golang-library, golang-package, json
- Language: Go
- Homepage:
- Size: 244 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# json
Copy of Golang's json library with IsZero feature from [CL13977](https://go-review.googlesource.com/c/go/+/13977/)
## Usage
Exactly the same as Go's [JSON](https://pkg.go.dev/encoding/json). Plus...
```go
package main
import (
"fmt"
"github.com/infiniteloopcloud/json"
)
type nullString struct {
Valid bool
String string
}
func (n nullString) IsZero() bool {
return !n.Valid
}
type RandomDataSet struct {
Data1 nullString `json:"data1,omitempty"`
Data2 nullString `json:"data2,omitempty"`
}
func main() {
result, err := json.Marshal(RandomDataSet{Data1: nullString{Valid: false, String: "test"}})
if err != nil {
panic(err)
}
fmt.Println(string(result))
// Output: {}
result, err = json.Marshal(RandomDataSet{Data1: nullString{Valid: true, String: "test"}})
if err != nil {
panic(err)
}
fmt.Println(string(result))
// Output: {"data1":{"Valid":true,"String":"test"}}
}
```
## Contribution
These changes automatically generated by [jsongen](https://github.com/infiniteloopcloud/jsongen).
```shell
git checkout -b go1.x.x
jsongen --version go1.x.x --destination .
```