json.Marshal() sorts maps when it is encoding them, which does not seem right
package main
import (
"fmt"
"encoding/json"
)
func main() {
fmt.Println("Go just broke my web form ...")
countries := map[string]string {
"USA" : "United States of America",
"Afg" : "Afghanistan",
}
jsonBytes, _ := json.MarshalIndent(countries, "", " ")
fmt.Println(countries)
fmt.Println(string(jsonBytes))
}
Outputs
Go just broke my web form ...
map[USA:United States of America Afg:Afghanistan]
{
"Afg": "Afghanistan",
"USA": "United States of America"
}
Instead of
...
{
"USA": "United States of America",
"Afg": "Afghanistan"
}
Which basically would mean that I would have change my data into
{
"countries" : {
"Afg": "Afghanistan",
"USA": "United States of America"
}
"order" : [
"USA",
"Afg"
]
}
It got looked at right away by one of the the encoding/json authors and he closed it as "WorkingAsIntended".