Created
May 19, 2017 20:24
-
-
Save esell/2c280ab1efae37e0b4d87f40d81381b5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type MyTemplate struct { | |
ContentVersion string `json:"contentVersion"` | |
// Resources could be other types outside of Resource1, hence the []string | |
Resources []string `json:"resources"` | |
} | |
type Resource1 struct { | |
ResourceType string `json:"-"` | |
APIVersion string `json:"apiVersion"` | |
Comments string `json:"comments"` | |
Type string `json:"type"` | |
} | |
var Resources = make(map[string]Resource1) | |
finalTemplate := MyTemplate{ContentVersion: "1.0.0.0"} | |
for k, v := range Resources { | |
if len(k) > 1 { | |
blah, err := json.Marshal(v) | |
if err != nil { | |
} | |
finalTemplate.Resources = append(finalTemplate.Resources, string(blah)) | |
} | |
} | |
finalBlah, err := json.Marshal(finalTemplate) | |
if err != nil { | |
} | |
fmt.Printf("%s\n", finalBlah) | |
// CURRENT OUTPUT | |
{ | |
"$schema":"", | |
"contentVersion":"1.0.0.0", | |
"resources":[ | |
"{ ///// Notice the quote? | |
\"apiVersion\":\"\", | |
\"comments\":\"\", | |
\"type\":\"Microsoft.Network/virtualNetworks\" | |
}" ///// Notice the quote? | |
] | |
} | |
// EXPECTED OUTPUT | |
// OUTPUT | |
{ | |
"$schema":"", | |
"contentVersion":"1.0.0.0", | |
"resources":[ | |
{ | |
\"apiVersion\":\"\", | |
\"comments\":\"\", | |
\"type\":\"Microsoft.Network/virtualNetworks\" | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment