Skip to content

Instantly share code, notes, and snippets.

@psu
Last active March 5, 2024 10:13
Show Gist options
  • Save psu/59c3cc2024af28e76ce1f1cbeb0923d7 to your computer and use it in GitHub Desktop.
Save psu/59c3cc2024af28e76ce1f1cbeb0923d7 to your computer and use it in GitHub Desktop.
JQ & Qlerify commands
###############################################
# 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