go icon indicating copy to clipboard operation
go copied to clipboard

Mapping inner json field to outer tag in struct while marshalling.

Open Dilipchauhan1998 opened this issue 4 years ago • 0 comments

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?

Dilipchauhan1998 avatar Feb 04 '21 09:02 Dilipchauhan1998