Marshal dynamic JSON field tags in Go
问题 I'm trying to generate JSON for a Terraform file. Because I (think I) want to use marshalling instead of rolling my own JSON, I'm using Terraforms JSON format instead of the 'native' TF format. { "resource": [ { "aws_instance": { "web1": { "some": "data" } }] } resource and aws_instance are static identifiers while web1 in this case is the random name. Also it wouldn't be unthinkable to also have web2 and web3 . type Resource struct { AwsResource AwsResource `json:"aws_instance,omitempty"` }