Hi fernvale_54,
As mossglen_55 already pointed out, you can represent a value with a pointer to indicate that the corresponding data might be absent
type Entry struct {
Text *string `json:"bar"`
}
When using a value which could possibly be null, remember to check for null before treating that value as one that actually exists, or you'll hit panic: runtime error: invalid memory address or nil pointer dereference, something along these lines works:
var entry Entry
//...unmarsal into Entry
if entry.Text != nil {
// len() is safe in this branch
fmt.Println(len(*entry.Text))
}
For tidier JSON output, also investigate the omitempty and omitzero tags (omitzero arrived with go 1.24 and is fairly recent, so information about it might still be sparse)