How do I store and retrieve JSON documents in Go?

Go, JSON, Store, Retrieve, Documents
Learn how to store and retrieve JSON documents using Go programming language effectively.
package main import ( "encoding/json" "fmt" "os" ) type Person struct { Name string `json:"name"` Age int `json:"age"` Address string `json:"address"` } func main() { // Example: Creating a JSON document person := Person{Name: "Alice", Age: 30, Address: "123 Main St"} // Storing JSON document to a file file, _ := json.MarshalIndent(person, "", " ") _ = os.WriteFile("person.json", file, 0644) // Retrieving JSON document from a file var retrievedPerson Person jsonData, _ := os.ReadFile("person.json") json.Unmarshal(jsonData, &retrievedPerson) fmt.Printf("Retrieved Person: %+v\n", retrievedPerson) }

Go JSON Store Retrieve Documents