Structures and JSON
Explore how to use Go struct tags to control JSON marshaling. Understand the use of omitempty to skip empty fields and the '-' tag value to exclude sensitive data from JSON output, enhancing your UNIX system programming in Go.
We'll cover the following...
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:
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 ...