package optional_test import ( "encoding/json" "fmt" "log" "xengineering.eu/optional-go/optional" ) type Message struct { Present optional.Optional[string] Null optional.Optional[bool] Missing optional.Optional[int] } func Example_json() { text := `{ "present": "value", "null": null }` var msg Message err := json.Unmarshal([]byte(text), &msg) if err != nil { log.Fatal(err) } fmt.Printf( "%t %t %t", msg.Present.Exists, msg.Null.Exists, msg.Missing.Exists, ) // Output: true false false }