Last active
July 12, 2020 00:37
-
-
Save stnguyen90/f526bd8025746b7dc85e239270a4cff1 to your computer and use it in GitHub Desktop.
Handling Null JSON Arrays in Go - Manual Make
This file contains 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" | |
) | |
// Bag holds items | |
type Bag struct { | |
Items []string | |
} | |
// PrintJSON converts payload to JSON and prints it | |
func PrintJSON(payload interface{}) { | |
response, _ := json.Marshal(payload) | |
fmt.Printf("%s\n", response) | |
} | |
func main() { | |
bag1 := Bag{} | |
bag1.Items = make([]string, 0) | |
PrintJSON(bag1) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment