https://github.com/chenhg5/jsonmap
jsonmap: map the enum value to human-readable text defined in the struct tag when doing json marshal and unmarshal operations
https://github.com/chenhg5/jsonmap
Last synced: 2 months ago
JSON representation
jsonmap: map the enum value to human-readable text defined in the struct tag when doing json marshal and unmarshal operations
- Host: GitHub
- URL: https://github.com/chenhg5/jsonmap
- Owner: chenhg5
- Created: 2023-08-24T10:17:07.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2023-08-25T02:27:03.000Z (almost 2 years ago)
- Last Synced: 2025-01-25T11:26:44.217Z (4 months ago)
- Language: Go
- Homepage:
- Size: 7.81 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# jsonmap
golang json serialization field mapper, using struct tag## Usage
```go
package mainimport (
"encoding/json"
"fmt""github.com/chenhg5/jsonmap"
)func main() {
var text = `{
"type": "cow"
}`type Animal struct {
Type uint8 `json:"type" jsonmap:"0:dog;1:cat;2:cow;3:others"`
}var animal = new(Animal)
_ = jsonmap.Unmarshal([]byte(text), animal)
fmt.Printf("%+v\n", animal)// &Animal{Type: 2}
res, _ := jsonmap.MarshalIndent(animal, "", " ")
fmt.Println(string(res))// {"type": "cow"}
}
```