So I have an array of struct Recipe it contains some properties and one of the properties is the struct Source, I want to convert the entire array to json but only the Source property of the Recipe struct
Code: https://play.golang.org/p/E71d4xzNM4
Result:
[
{
"Id": 1,
"Title": "Fine Peanutbutter",
"Description": "The best peanutbutter in the world",
"Source": {
"Name": "Peter",
"Address": "32121 Little Midge"
},
"Price": 49
},
{
"Id": 2,
"Title": "Fine Jelly",
"Description": "The best Jelly in the world",
"Source": {
"Name": "Peter",
"Address": "32121 Little Midge"
},
"Price": 39
}
]
Wanted Result:
[
{
"Name": "Peter",
"Address": "32121 Little Midge"
},
{
"Name": "Peter",
"Address": "32121 Little Midge"
}
]
How do I get this without looping through the entire array and creating a new array struct and doing a json marshal on that one