Skip to content

Instantly share code, notes, and snippets.

@linw1995
Created October 14, 2021 13:46
Show Gist options
  • Save linw1995/c5f022358894f91ddc5833ed683a535f to your computer and use it in GitHub Desktop.
Save linw1995/c5f022358894f91ddc5833ed683a535f to your computer and use it in GitHub Desktop.
json.Unmarshal can parse null into empty array
package main
import (
"fmt"
"encoding/json"
)
func main() {
var (
lst []string
err error
)
err = json.Unmarshal(([]byte)("null"), &lst)
fmt.Println(lst, err)
err = json.Unmarshal(([]byte)("[]"), &lst)
fmt.Println(lst, err)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment