Last active
May 25, 2023 05:27
-
-
Save nikzayn/49e9ec6dfc5edf9ac27e01bbbbfcea95 to your computer and use it in GitHub Desktop.
Example to show the output of json using omitempty tag
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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