abhimanyu003 / sttr

cross-platform, cli app to perform various operations on string

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

RESDXChgfore9hing opened this issue · comments

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*.

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

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"

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.

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

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