Created
October 18, 2024 10:43
-
-
Save lyda/b52a68de3306b4679dca141fc6bd314e to your computer and use it in GitHub Desktop.
Spew some JSON to a named file
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
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