Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save stnguyen90/f526bd8025746b7dc85e239270a4cff1 to your computer and use it in GitHub Desktop.
Save stnguyen90/f526bd8025746b7dc85e239270a4cff1 to your computer and use it in GitHub Desktop.
Handling Null JSON Arrays in Go - Manual Make
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