Skip to content

Instantly share code, notes, and snippets.

@nikzayn
Last active May 25, 2023 05:27
Show Gist options
  • Save nikzayn/49e9ec6dfc5edf9ac27e01bbbbfcea95 to your computer and use it in GitHub Desktop.
Save nikzayn/49e9ec6dfc5edf9ac27e01bbbbfcea95 to your computer and use it in GitHub Desktop.
Example to show the output of json using omitempty tag
package main
import (
"encoding/json"
"fmt"
)
type Person struct {
Name string
Age int `json:",omitempty"`
}
func main() {
p := Person{
Name: "Nikhil",
}
b, _ := json.Marshal(d)
fmt.Println(string(b))
}
//Output
- {"Name":"Nikhil"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment