go
go copied to clipboard
Mapping inner json field to outer tag in struct while marshalling.
I have a json { "address" : { "name" : "ABC", "primary_address": "XYZ" } "pin_code" : "638332" }
and struct
type struct Address {
PrimaryAddress. string json:"primary_address"
PinCode string json:"pin_code"
}
I want to unmarshall the json into given struct where address->primary_address should be mapped to primary_address tag in struct.
Note : I don't want to change the structure of the given struct. How can we achieve this?