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

Sheriff reorders the fields alphabetically #49

Closed
skhattane opened this issue Mar 23, 2024 · 3 comments · Fixed by #52
Closed

Sheriff reorders the fields alphabetically #49

skhattane opened this issue Mar 23, 2024 · 3 comments · Fixed by #52

Comments

@skhattane
Copy link

The usage of sheriff.Marshal(options, data) reorganizes the fields alphabetically instead of keeping the original order. (v2.0.0-beta.1)

Expected

{
    "id": "a5b002bb-b63d-4192-b665-ec4dadcb036b",
    "name": "test",
    "createdAt": "2024-03-17T06:56:04Z",
    "updatedAt": "2024-03-17T06:56:04Z"
}

Actual behavior

{
    "createdAt": "2024-03-17T06:56:04Z",
    "id": "a5b002bb-b63d-4192-b665-ec4dadcb036b",
    "name": "test",
    "updatedAt": "2024-03-17T06:56:04Z"
}
@Chalwe19
Copy link

Chalwe19 commented Apr 5, 2024

+1

@mweibel
Copy link
Collaborator

mweibel commented Apr 5, 2024

sheriff.Marshal() uses as a target a map[string]interface{} to achieve the flexibility it needs to do it's job. json.Marshal sorts maps. I'm not aware of a way to keep the original order.

If you know a way, please propose a solution and we can talk about a PR. Or submit a PR directly but depending on the complexity I may decline to merge it.

Reasoning behind is that while it may be slightly annoying, JSON is a format mostly read by machines and not by humans and for machines order does not matter.

@mweibel
Copy link
Collaborator

mweibel commented May 31, 2024

FYI this is fixed with release v2.0.0-beta.2. See README on instructions for adding ordered map output.

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