in reply to Outputting JSON with sorted names/keys

Hi pryrt, take a look at jq. I almost always pipe JSON output through it, whether from scripts or one-liners. (Maybe its sort_by is enough?)

Hope this helps!


The way forward always starts with a minimal test.
  • Comment on Re: Outputting JSON with sorted names/keys

Replies are listed 'Best First'.
Re^2: Outputting JSON with sorted names/keys
by pryrt (Abbot) on Jan 26, 2020 at 21:21 UTC

    ooh. jq looks interesting. If I start doing more with JSON, I'll probably want to play with that, because a structure-aware sed-like tool would be quite useful.

      I usually plug jq as being like "awk for JSON data" (in that just I think of it more in terms of doing "awk-y" things with it than sed like things (e.g. I want to pull these "fields" (some set of keys from an object) out of each line (each textual line of the file being a JSON object)).

      At any rate seconding it as a highly recommended useful thing to have lying around on your PATH somewhere. Check out the @csv and @sh formatting modifiers which can be handy wrangling JSON from the command line (search for "Format strings and escaping" in the manual).

      The cake is a lie.
      The cake is a lie.
      The cake is a lie.