Skip to content

Instantly share code, notes, and snippets.

@lyda
Created October 18, 2024 10:43
Show Gist options
  • Save lyda/b52a68de3306b4679dca141fc6bd314e to your computer and use it in GitHub Desktop.
Save lyda/b52a68de3306b4679dca141fc6bd314e to your computer and use it in GitHub Desktop.
Spew some JSON to a named file
func spewJSON(fn, data string) {
w, err := os.Create(fn)
if err != nil {
panic(err)
}
defer w.Close()
var v any
json.Unmarshal([]byte(data), &v)
e := json.NewEncoder(w)
e.SetIndent("", " ")
e.Encode(v)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment