package main import ( "encoding/json" "fmt" ) type Test struct { Name string `json:"name"` Name2 string `json:"name2"` Name3 string `json:"name3,omitempty"` Age int32 `json:"age"` NotSer string `json:"-"` Bool bool `json:"bool"` BoolInStr bool `json:"bool_in_str,string"` } func main() { t := Test { Name: "hatter", Name2: "", Name3: "", Age: 18, NotSer: "not ser!", Bool: true, BoolInStr: true, } s, err := json.Marshal(t) if err != nil { fmt.Println("ERROR: ", err) return } fmt.Println("JSON: ", string(s)) }