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

possibility of making the json escape function not sorting the input? #30

Closed
RESDXChgfore9hing opened this issue Dec 24, 2022 · 5 comments
Labels
enhancement New feature or request

Comments

@RESDXChgfore9hing
Copy link

It would be useful to have a extra flag to make sure the output keys is not sorted.
Since sometimes,I need to feed it to other cli tool or onlt want sttr to just escape it directly will keeping it,unsorted*.

@abhimanyu003
Copy link
Owner

Hello @RESDXChgfore9hing
Thanks so much for reporting this issue, looks like I have to figure out some solution for this.
There is also a bug report open in go internal repo encoding/json: no way to preserve the order of map keys

In sttr code can be found here processors/json.go#L315

@abhimanyu003 abhimanyu003 added the enhancement New feature or request label Dec 25, 2022
@RESDXChgfore9hing
Copy link
Author

it seems like encoding/json dont intend to fix and others suggested to use other library>

For the people who stumble upon this issue from Google, the following two libraries (pick one) can help you if you need an ordered JSON map:

https://gitlab.com/c0b/go-ordered-json
https://github.com/iancoleman/orderedmap

Also, for reference, see this common StackOverflow answer:
https://stackoverflow.com/questions/25182923/serialize-a-map-using-a-specific-order


I think we would be better of creating a "json-escape-no-sort" and making the current one "json-escape-with-sort"

@abhimanyu003
Copy link
Owner

Hello @RESDXChgfore9hing
This is fixed in the latest commit ef78637
You can get the specific commit using

go install github.com/abhimanyu003/sttr@ef78637820bd25a27a62c6b4de467b026fe59b88

I will do a tagged release this week. Have to look into few things at other area as well.

@RESDXChgfore9hing
Copy link
Author

damn thats fast,looks good. will wait for release at weekend

@abhimanyu003
Copy link
Owner

A new tagged release version is out now.
Thanks again so much for reporting this issue.

https://github.com/abhimanyu003/sttr/releases/tag/v0.2.14

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