Custom JSON marshalling of map of maps

I have written some code to custom unmarshal json data to a map[string]map[string]*template.Template. The unmarshaller is responsible for parsing the template data, which means that errors are likely to occur with specific templates, and in this case I would like to raise an error to the user that is annotated with the two string keys, so that the user knows which template failed.

Ive written the code (https://play.golang.org/p/4Fi9i3fphuo) which works failrly well, but I cant help wondering if there is a cleaner or more efficient way to do this. One problem I can see is that I need to remarshal the interface{} data from the map[string]interface{}, before I can do a recursive call to json.Unmarshal() (see comments). This seems inefficient… Is there a better way to do this?

I would like to retain the custom unmarshallers for all three levels as I would like to be able to unmarshal other JSON data to map[string]*template.Template.

Any thoughts on this…?

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.