orderedmap
orderedmap copied to clipboard
Preserve json keys order while marshalling in Go
https://goplay.tools/snippet/DmuiHIvVNdh
After marshalling returns nil, the orderedmap library does not implement Go's json.Marshaler interface directly.
This has been raised before: https://github.com/elliotchance/orderedmap/issues/12
The problem is that while this type can be opinionated about how it's encoded it's not safe to assume the same is true for decoding. For example, multiple JSON formats would be acceptable for decoding and it's not sensible to settle on one.
That is why you should create your own marshaller for the symmetrical encode/decode format you desire. I'm open to accepting these new types into the library, but with some discussion first.