Skip to content

Preserve json keys order while marshalling in Go #56

Open

Description

@wathika-eng

https://goplay.tools/snippet/DmuiHIvVNdh

After marshalling returns nil, the orderedmap library does not implement Go's json.Marshaler interface directly.

Activity

  1. elliotchance commented on Jul 9, 2025

    @elliotchance
    Owner

    This has been raised before: #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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions