import (
    "encoding/json"
    "fmt"
    "io"
)
func PrintPrettyJSON(data any, writer io.Writer) error {
    b, err := json.MarshalIndent(data, "", "    ")
    if err != nil {
        return err
    }
    content := string(b)
    _, err = fmt.Fprintf(writer, "%s\n", content)
    return err
}

On Thursday, September 29, 2022 at 1:47:22 PM UTC-4 Mahesh Sharma wrote:

> Hi, 
> I'm collecting some JSON from an end point.  I can print this to screen:
>   fmt.Printf("%s\n", bodyText).
>
> I'm struggling to figure how to write the bodyText to a file.
>
> Any help appreciated. 
>
>
>
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/015e47eb-8399-4a61-bcd6-14b01a76b9a5n%40googlegroups.com.

Reply via email to