package main
import (
"encoding/json"
"fmt"
)
type Person struct {
Name string `json:"name"`
Age int `json:"age"`
Email string `json:"email,omitempty"`
}
func main() {
// Step 1: Create a struct representing the data structure
person := Person{
Name: "John Doe",
Age: 30,
Email: "[email protected]",
}
// Step 2: Marshal the struct into a JSON string
jsonData, err := json.Marshal(person)
if err != nil {
fmt.Println("Error marshalling JSON:", err)
return
}
// Step 3: Print the JSON string
fmt.Println(string(jsonData))
}