How to beautifully format JSON in Go: a detailed guide
Hello! I'm new to Go and working on a project where I need to output JSON in a readable format. I have a data structure that I serialize to JSON using `json.Marshal()`, but the output is a single-line string without indentation or line breaks. This is very inconvenient for debugging and logs.
Here is my code:
```go
package main
import (
"encoding/json"
"fmt"
)
type User struct {
Name string
Age int
Email string
Address Address
}
type Address struct {
City string
Country string
}
func main() {
user := User{
Name: "Ivan Ivanov",
Age: 30,
Email: "ivan@example.com",
Address: Address{
City: "Moscow",
Country: "Russia",
},
}
jsonData, err := js