Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
luispabon opened this issue Jan 25, 2019 · 1 comment
Open

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

luispabon opened this issue Jan 25, 2019 · 1 comment

Comments

@luispabon
Copy link

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

@luispabon luispabon changed the title Ordered object: array within array doesn't respect order Ordered object: object within json doesn't respect order Jan 25, 2019
@virtuald
Copy link
Owner

Hm, I thought it did that -- though I didn't write the code, just hosting it for convenience. :) If it doesn't, then that sounds like a bug to me. I'm on vacation until mid-February, but I'm happy to review any pull requests with that testcase added.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants