Open slafs opened 2 years ago
BTW this tool is fantastic and helps me a lot! Thanks for creating it :)
--no-sort
tells gron not to sort the output. It doesn't guarantee a stable order - if you want that, let it sort. The instability comes from the underlying Go map
object, which randomizes string hashing functions.
Well, I guessed that might be the cause, but the underlying implementation shouldn't matter, right? The option is confusing when it works this way. What's the use of a non-sorted output if the input is being modified in the first place 😅?
Hi, I just tried with the tool I wrote ( https://github.com/adamritter/fastgron ), it preserves the order with gron (I'm not sure about ungron though yet :( )
for i in $( seq 1000 ); do echo '{"z": "first", "a": "last"}' | gron --no-sort | column -x; done | sort | uniq -c;
130 json = {}; json.a = "last"; json.z = "first"; 870 json = {}; json.z = "first"; json.a = "last"; (base) ➜ ~/Documents/GitHub/fastgron/fastgron git:(main) for i in $( seq 1000 ); do echo '{"z": "first", "a": "last"}' | fastgron --no-sort | column -x; done | sort | uniq -c;
1000 json = {} json.z = "first" json.a = "last"
+1 to --no-sort
preserving input order if that's not to difficult to implement. Right now there is no way to retain order, but order often is often explicitly set in JSON objects to aid in interpretation / human-legibility.
For a simple JSON doc
gron --no-sort
keeps producing wrong results at around 12% rate.Tried it with:
Tried it with: