You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add a struct tag for maps to sort by key while marshalling.
type MyStruct struct {
Results map[string]int `json:",ordered"`
}
This would collect the keys of the map (which always resolve to strings), sort them using sort.Strings, and then encode each key/value in that order. This proposal is in response to seeing 2 instances of people asking how to encode a map with consistent ordering.
Edit: This would also help with unit testing.
Edit2: It seems this is already implemented without a struct tag - disregard.
The text was updated successfully, but these errors were encountered:
Description
Add a struct tag for maps to sort by key while marshalling.
This would collect the keys of the map (which always resolve to strings), sort them using
sort.Strings
, and then encode each key/value in that order. This proposal is in response to seeing 2 instances of people asking how to encode a map with consistent ordering.Edit: This would also help with unit testing.
Edit2: It seems this is already implemented without a struct tag - disregard.
The text was updated successfully, but these errors were encountered: