/*
set default values for a struct being Unmarshaled from json
*/
package main
import (
"encoding/json"
"fmt"
)
type Out struct {
A string `json:"a"`
B string `json:"b"`
C string `json:"c"`
D int `json:"d"`
}
func main() {
in := []byte(`{"a":"1"}`)
out := Out{
A: "defaultA",
B: "defaultC",
C: "defaultD",
D: 99,
}
json.Unmarshal(in, &out)
fmt.Printf("%+v\n ", out)
}
For further actions, you may consider blocking this person and/or reporting abuse
Top comments (0)