package main
import (
"encoding/json"
"fmt"
)
type OriginalStruct struct {
OldKey string `json:"old_key"`
}
type ModifiedStruct struct {
NewKey string `json:"new_key"`
}
func main() {
// Create an instance of the original struct
originalInstance := OriginalStruct{OldKey: "value"}
// Convert the original struct to JSON
originalJSON, err := json.Marshal(originalInstance)
if err != nil {
fmt.Println("Error marshalling original struct:", err)
return
}
fmt.Println("Original JSON:", string(originalJSON))
// Unmarshal the JSON into the modified struct
var modifiedInstance ModifiedStruct
err = json.Unmarshal(originalJSON, &modifiedInstance)
if err != nil {
fmt.Println("Error unmarshalling into modified struct:", err)
return
}
// Print the modified struct
fmt.Println("Modified Struct:", modifiedInstance)
}