|
|
|
|
|
by tynorf
2401 days ago
|
|
One technique I use is to create a struct that mirrors the layout of the target struct, then just cast between them. So if you have a type Person struct {
FirstName string `json:"first_name"`
}
And you get json like `{"name": "Alice"}`, you can decode it something like this: var doc struct {
FirstName string `json:"name"`
}
json.Unmarshal(data, &doc)
person := Person(doc)
I have not looked at the assembly so I can't say whether this incurs extra overhead or not. |
|