You can create a map in Go, fill it with the name in various languages, serialize to JSON and send. Same thing as what Go struct to JSON does, can be achieved via a Go map.
Hi, thanks for the suggestion, but as you probably know yourself that won’t work as the struct must have a “named” (exported) field which will “leak” into the resulting json:
type Person struct {
Uid string `json:"uid,omitempty"`
Name map[string]string `json:"name,omitempty"`
DType []string `json:"dgraph.type,omitempty"`
}
No, even removing the json tag does not help the situation.
I’m thinking the only way to work around this is to create a custom json.Marshaller, but oh my` I so wanted to avoid doing that, unless there is something I am really missing here.
Well, it’s not pretty, but you could create a map for Name, and marshal it separately from Person. Then, stitch them together by removing the last ‘}’ and first ‘{’ of them.