Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.Sign up
encoding/json: document that object keys are sorted #15424
If you call json.Marshal with a map, it sorts the keys. If you do a search, you will find a Stack Overflow page explaining this. However, this behavior isn't mentioned in the godoc.
It's useful to assume that the emitted JSON will be deterministic, since then you can use string equality or compare hashes to look for duplicates and compare the emitted JSON to a golden copy in tests. But since this property isn't mentioned, it's unclear whether users can rely on the emitted JSON remaining the same in new versions of Go.
Many people will do it anyway, so perhaps we should make it official?