Skip to content

Instantly share code, notes, and snippets.

@petrowsky
Last active August 18, 2022 03:30
Show Gist options
  • Save petrowsky/d8fd7e0fef362ddab52816cc7f8bdcb1 to your computer and use it in GitHub Desktop.
Save petrowsky/d8fd7e0fef362ddab52816cc7f8bdcb1 to your computer and use it in GitHub Desktop.
Let ( [
$$JSON = If ( IsEmpty ( $$JSON );
BE_HTTP_GET ( "https://api.github.com/repos/GoyaPtyLtd/BaseElements-Plugin/commits" );
/*else*/
$$JSON )
];
// BE_JSON_jq ( $$JSON ; "." ; "") // All JSON: dot means "root".
// BE_JSON_jq ( $$JSON ; ".[]" ; "") // Now get the elements of the array.
// BE_JSON_jq ( $$JSON ; ".[2]" ; "") // Just one specific element.
// BE_JSON_jq ( $$JSON ; ".[2:5]" ; "") // Range of elements.
// BE_JSON_jq ( $$JSON ; ".[].sha" ; "") // Pulling just one key from each element.
// BE_JSON_jq ( $$JSON ; ".[].commit.author.name" ; "") // Pulling further down into other objects.
// BE_JSON_jq ( $$JSON ; ".[] | length" ; "") // Pipe each element to length command.
// BE_JSON_jq ( $$JSON ; ".[] | .sha, .commit.author.name" ; "") // Get multiple elements with comma.
// BE_JSON_jq ( $$JSON ; ".[] | .commit.author.name + \" \" + .sha" ; "") // Or combine them with a plus.
// BE_JSON_jq ( $$JSON ; ".[] | .commit.author + .author" ; "") // Or combine two objects together.
// BE_JSON_jq ( $$JSON ; "[.[] | .commit.author + .author]" ; "") // Make your new results into an array.
// BE_JSON_jq ( $$JSON ; "map(.commit.author + .author)" ; "") // You can also use the map() builtin function.
// BE_JSON_jq ( $$JSON ; "{authorship:.[] | (.commit.author + .author)}" ; "") // Or into objects. Note the parenthesis!
// BE_JSON_jq ( $$JSON ; "[.[] | keys]" ; "") // Need just the keys?
// BE_JSON_jq ( $$JSON ; "[.[] | keys] | unique[0]" ; "") // But just one set?
// BE_JSON_jq ( $$JSON ; "[.[] | keys] | unique[0] | reverse" ; "") // In reverse for some reason?
// BE_JSON_jq ( $$JSON ; ".[0].commit.author | has(\"name\")" ; "") // Determine if key exists.
// BE_JSON_jq ( $$JSON ; ".[0].commit.author | {dev:.name, mail:.email}" ; "") // New object with different keys?
// BE_JSON_jq ( $$JSON ; ".[].commit.author | {dev:.name, mail:.email}" ; "") // For all elements?
// BE_JSON_jq ( $$JSON ; "[.[].commit.author | {dev:.name, mail:.email}] | unique" ; "") // Only unique ones?
// BE_JSON_jq ( $$JSON ; "map(.commit.author | {dev:.name, mail:.email}) | unique" ; "") // Remember map()?
// BE_JSON_jq ( $$JSON ; "[.[] | .commit.author + .author | del(.email)]" ; "") // Removing a key.
// BE_JSON_jq ( $$JSON ; "[.[] | getpath([\"commit\",\"author\"],[\"author\",\"url\"])]" ; "") // getpath() gets specific stuff...
// BE_JSON_jq ( $$JSON ; ".[] | .commit.author + {url:.author.url}" ; "") // But it's easier to do this.
// BE_JSON_jq ( $$JSON ; "[.[] | .commit.author + {url:.author.url} | del(.date,.email)] | unique" ; "") // Then this.
// BE_JSON_jq ( $$JSON ; "[.[] | select(.commit.committer.name == \"GitHub\") | .sha]" ; "") // Use select to find specific things.
// BE_JSON_jq ( $$JSON ; ".[] | select(.commit.committer.name == \"GitHub\") | .sha" ; "-r") // Need just raw data? Use --raw-output / -r.
// BE_JSON_jq ( $$JSON ; "[.[] | .commit.verification.verified] | any" ; "") // Determine if an array of booleans has any true values.
// BE_JSON_jq ( $$JSON ; "[.[] | .commit.verification.verified] | all" ; "") // Determine if an array of booleans has all true values.
// BE_JSON_jq ( $$JSON ; "[.[] | .commit ]| sort_by(.message) | .[] | .message" ; "") // Use sort_by() to sort things.
// BE_JSON_jq ( $$JSON ; "[.[] | .commit.message] | sort" ; "") // Or the shorter method in this case.
BE_JSON_jq ( $$JSON ; "[.[] | select(.commit.message | contains(\"BE_RegularExpression\") )]" ; "") // Extract via a contains filter.
)
// Can't get enough? Try this https://github.com/stedolan/jq/wiki/Cookbook
/*
Options
--version
--seq
--seq option.
--stream
--slurp/-s
--raw-input/-R
--null-input/-n
--compact-output / -c
--tab
--indent n
--color-output / -C
--monochrome-output / -M
--binary / -b
--ascii-output / -a
--unbuffered
--sort-keys / -S
--raw-output / -r
--join-output / -j
--nul-output / -0
--from-file filename
--exit-status
--arg name value
--arg foo bar, then $foo is available in the program and has the value "bar". Note that value will be treated as a string, so --arg foo 123 will bind $foo to "123".
--argjson name JSON-text
--argjson foo 123, then $foo is available in the program and has the value 123.
--slurpfile variable-name filename
--slurpfile foo bar, then $foo is available in the program and has an array whose elements correspond to the texts in the file named bar.
--rawfile variable-name filename
--rawfile foo bar, then $foo is available in the program and has a string whose contents are to the texs in the file named bar.
--argfile variable-name filename
--slurpfile instead.
--slurpfile, but when the file has just one text, then that is used, else an array of texts is used as in --slurpfile.)
--args
--jsonargs
--run-tests [filename]
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment