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

Preserve JSON keys order #2970

Closed
pothitos opened this issue May 22, 2024 · 10 comments
Closed

Preserve JSON keys order #2970

pothitos opened this issue May 22, 2024 · 10 comments
Assignees
Labels
enhancement New feature or request

Comments

@pothitos
Copy link
Contributor

pothitos commented May 22, 2024

Is your feature request related to a problem? Please describe.
Good morning Amir and thank you again very much for this awesome tool! The JSON keys in the logs are always sorted alphabetically.

Describe the solution you'd like
I was wondering if there's a way to keep their order as is. Sometimes, the existing order is more intuitive as the alphabetical one.

Describe alternatives you've considered
I think there isn't an option for this. I couldn't also find where in the code the keys are sorted.

Additional context
Edit: An example is that the following

# docker logs mycontainer
{"b":1, "a":1}

is displayed in Dozzle as

a=1 b=1
@pothitos pothitos added the enhancement New feature or request label May 22, 2024
@amir20
Copy link
Owner

amir20 commented May 22, 2024

Interesting ask! I agree JSON order matters. I am not actually sorting it in Dozzle. Looks like Go is doing it as described in golang/go#27179

There is a couple of solutions suggested there. I am not all too sure if they will work. But seems like the issue is converting JSON --> map --> back to JSON.

@amir20
Copy link
Owner

amir20 commented May 22, 2024

So I used orderedmap.New() from https://github.com/iancoleman/orderedmap and it seems to work. 🚀

I haven't looked at all the details and what other regression issues maybe introduced.

Can you test using amir20/dozzle:pr-2971?

@pothitos
Copy link
Contributor Author

Sure, Amir! Many thanks for the quick implementation!

It seems to work on my site too! I'll check it more thoroughly later. Nevertheless, the info/warn/error colored bullets have disappeared.

@amir20
Copy link
Owner

amir20 commented May 22, 2024

Nevertheless, the info/warn/error colored bullets have disappeared.

Hmm good catch. I think I know why. Do a little more testing and see what else could have broken.

@amir20
Copy link
Owner

amir20 commented May 22, 2024

928c170 should fix it. Pull again.

@pothitos
Copy link
Contributor Author

It did the trick! Great job, Amir! I already use it, and if I find something else I'll come back, but I don't think so 🙌

@amir20
Copy link
Owner

amir20 commented May 22, 2024

If you can do a little more testing, I can merge.

@pothitos
Copy link
Contributor Author

So far so good, Amir! I think we can consider this as implemented! Many thanks again for the speed of light commits 🙇‍♀️

@amir20 amir20 closed this as completed in 1d1f3ed May 22, 2024
@amir20
Copy link
Owner

amir20 commented May 22, 2024

Will release a patch tomorrow. Working on swarm support so v7 will be coming out soon.

@pothitos
Copy link
Contributor Author

Great news, Amir! Thank you very much for your efforts and contributions to the open source and Docker community 🙏

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

No branches or pull requests

2 participants