Last active
March 5, 2024 10:13
-
-
Save psu/59c3cc2024af28e76ce1f1cbeb0923d7 to your computer and use it in GitHub Desktop.
JQ & Qlerify commands
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
############################################### | |
# JQ & Qlerify commands -- Pontus Sundén 2024 # | |
############################################### | |
### BASICS | |
# List event descriptions | |
jq '.eventsJson[].description' | |
# List events with type appended (if other than "Task) | |
jq '.eventsJson[] | .description+(if (.type|contains("Task")|not) then " - "+(.type|match(":(.+)")|.captures[0].string) else "" end)' | |
# List swimlanes | |
jq '.lanes[] | .name' | |
# List custom definitions | |
jq '. | to_entries[] | select(.key | endswith("Definition") ) | .value | .title+": "+.description ' | |
# List all cards | |
jq '.eventsJson[] | .requirementsJson[]? | .description' | |
# List card of type $select | |
jq --arg select "system" '.eventsJson[] | .requirementsJson[]? | select((.cardType.title|ascii_downcase)==($select|ascii_downcase)) | .description' | |
### ADVANCED | |
# Output headerless CSV with: event_position, event_description, card_type, card_description | |
jq --raw-output ' | |
.eventsJson | to_entries | map(.value.position=.key+1) | map(.value) | .[] | | |
.description as $parent | .position as $position | | |
.requirementsJson[]? | | |
[$position, $parent, .cardType.title, .description] | @csv | | |
gsub("<p>(\\s|<br(\\s/)?>)*</p>";"";"m") | | |
gsub("<br(\\s/)?>|</p>\\s*<p>";"\n") | | |
gsub("<[^>]*>";"") | |
' | |
### UTILS | |
# Include an element "position" denoting position for each object in an array | |
#replace this | |
jq '... | .arrayOfObjects[]' | |
#with this | |
jq '... | .arrayOfObjects | to_entries | map(.value.position=.key+1) | map(.value) | .[]' | |
# Strip HTML | |
jq '... | gsub("<[^>]*>"; "")' | |
# Try to keep newlines, then strip HTML | |
jq '... | gsub("<p>(\\s|<br(\\s/)?>)*</p>";"";"m") | gsub("<br(\\s/)?>|</p>\\s*<p>";"\n") | gsub("<[^>]*>";"")' | |
# Include first two characters of UUID | |
jq '... +" [" + (.id | match("^.{2}") | .string) + "]"' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment