Avatar ·

How to properly convert a Go struct to JSON and handle errors?

Hello everyone! I just started learning Go and encountered a problem when working with JSON. I'm trying to convert a struct to JSON, but nothing works. Here's my code: ```go package main import ( "fmt" "encoding/json" ) type Person struct { Name string Age int City string } func main() { p := Person{Name: "Ivan", Age: 30, City: "Moscow"} // Trying to convert to JSON result := json.Marshal(p) fmt.Println(result) } ``` Instead of normal JSON, I get a strange output like `[123 34 78 97...]`. I expected to see something like `{"Name":"Ivan","Age":30,"City":"Moscow"}`. Why is this happening? I read the documentation, but it's all written in a complicated way. Maybe I need to add some tags? Or am I calling the function incorrectly? Explain