Unmarshal JSON to map[string]struct on specific key

What would be a good way to unmarshal a JSON array into a map[string]struct on the basis of a specific key value of the JSON object?

I have an array of JSON objects, each JSON object containing an id key with a string value, my goal is to unmarshal each JSON object to the map with the map key being the id key from the JSON object.

Since the id is part of the object, unmarshal to []struct then build the map by looping through the array. Depending on the size of struct, it might be beneficial to use pointers to struct in the array and map (i.e., []*struct and map[string]*struct).

Thank you, I will try working this out.

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