Structures and JSON
Let’s learn about structures and JSON records.
We'll cover the following...
Coding example
Imagine that we have a Go structure that we want to convert into a JSON record without including any empty fields—the next widget illustrates how to perform that task with the use of omitempty
:
Press + to interact
// Ignoring empty fields in JSONtype NoEmpty struct {Name string `json:"username"`Surname string `json:"surname"`Year int `json:"creationyear,omitempty"`}
Lastly, imagine that we have some sensitive data on some of the fields of a Go structure that we do not want to include in the JSON records. We can do ...