Skip to content

Ordered object: object within json doesn't respect order #1

@luispabon

Description

@luispabon

I'm currently using your library to aid with message signature verification via a hash from a legacy system, where reconstructing the original structure in the exact same order is paramount.

Consider the following json:

Loaded into an OrderedMap then iterated through, like so (omitting error handling for brevity):

jsonString := `{
    "stuff": {
        "a": "1",
        "b": "12",
        "c": "654"
    },
    "yolo": "covfefe",
    "yay": 5
}`

var unmarshalled json.OrderedObject

err := json.Unmarshal([]byte(jsonString), &unmarshalled)

for key, item := range unmarshalled {
  // do some stuff
}

All the values at the root level are processed in the right order 100% of the time. The "stuff" array however is a map[string]interface{} which by its own nature is unordered. Therefore its contents can come out in any random order.

These should probably be unmarshalled into another OrderedObject

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