An open API service indexing awesome lists of open source software.

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

Awesome Lists containing this project

README

        

# jsonmap
golang json serialization field mapper, using struct tag

## Usage

```go
package main

import (
"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"}
}
```