I would like to know if it is possible to distinguish between void value and undefined field value.
Here is an example:
var jsonBlob = []byte(`[
{"Name": "A", "Description": "Monotremata"},
{"Name": "B"},
{"Name": "C", "Description": ""}
]`)
type Category struct {
Name string
Description string
}
var categories []Category
err := json.Unmarshal(jsonBlob, &categories)
if err != nil {
fmt.Println("error:", err)
}
fmt.Printf("%+v", categories)
Also available here: https://play.golang.org/p/NKObQB5j4O
Conclusion:
[{Name:A Description:Monotremata} {Name:B Description:} {Name:C Description:}]
So, in this example, you can distinguish a description from category B from category C?
I just want to be able to distinguish them in order to have different behavior in the program.
source
share