News for hackers. Stuff that matters.
Re:Gojq: Pure Go Implementation of Jq by fwip on Sunday August 21, 2022 @03:53PM (#32543790)
Not implementing key-sorting is a curious decision:

> gojq does not keep the order of object keys. I understand this might cause problems for some scripts but basically, we should not rely on the order of object keys. Due to this limitation, gojq does not have keys_unsorted function and --sort-keys (-S) option. I would implement when ordered map is implemented in the standard library of Go but I'm less motivated.

I feel like --sort-keys is most useful when it is producing output for tools that do not understand JSON - for example, generating diffs or hashes of the JSON string. There is value in the output formatting being deterministic for a given input.

Re:Gojq: Pure Go Implementation of Jq by eropple on Sunday August 21, 2022 @04:01PM (#32543864)
I agree with you that there's value to sorted keys from a presentational standpoint (we are not beep-boop robots, humans have to read this stuff too), but now there also exists a JSON canonicalization RFC that tools can/should follow (with all the usual caveats about canonicalization being fraught): https://www.rfc-editor.org/rfc/rfc8785
Re:Gojq: Pure Go Implementation of Jq by mdaniel on Sunday August 21, 2022 @05:57PM (#32544862)
I guess "Informational" is better than /dev/null, but unless everyone adopts it doesn't that run the risk of it just being My Favorite Canonicalization™?

Either way, I'm guessing if the gojq author has that much heartburn about implementing --sort-keys, --canonical is just absolutely off the table :-(

Re:Gojq: Pure Go Implementation of Jq by tialaramex on Sunday August 21, 2022 @08:47PM (#32546006)
> unless everyone adopts it doesn't that run the risk of it just being My Favorite Canonicalization

That's true regardless. The IETF has no enforcement arm. Even if people expend the effort to agree a standard, and make whatever signs and follow the rituals, if nobody implements it then de facto that isn't the standard after all.

Re:Gojq: Pure Go Implementation of Jq by fwip on Sunday August 21, 2022 @05:31PM (#32544661)
Thank you for letting me know! I hadn't thought to look.
Re:Gojq: Pure Go Implementation of Jq by krab on Monday August 22, 2022 @07:35AM (#32550016)
You can always add this feature but it's problematic to remove it.
Re:Gojq: Pure Go Implementation of Jq by renewiltord on Sunday August 21, 2022 @04:54PM (#32544313)
Could pipe through gron and sort to resort
Re:Gojq: Pure Go Implementation of Jq by Someone on Sunday August 21, 2022 @05:31PM (#32544667)
That helps when you want to sort by key, but not when you want to keep the order of object keys as in the input file.
Re:Gojq: Pure Go Implementation of Jq by pbsds on Tuesday August 23, 2022 @02:34AM (#32561212)
Gron has the same issue, as it too is written in go and randomizes key order.