JSON Tags
Control marshaling.
JSON Tags Control Marshaling
The encoding/json package uses json tags to decide the key names and rules when converting structs to and from JSON.
Default Field Names
Without tags, JSON keys match the exported field names exactly, including capitalization.
package main
import (
"encoding/json"
"fmt"
)
type User struct {
Name string
Age int
}
func main() {
b, _ := json.Marshal(User{"Ann", 30})
fmt.Println(string(b))
}