Reputation: 41
GitLab allows one to attach labels to issues. I would like to use jq to dig into the JSON representation of these labels. Here's the labels section of the JSON file for one issue:
"labels": [
"AI::Assessed",
"Pri::1 - High",
"Type::Investigation",
"v::Backlog"
]
How, with jq, can I get at the value of the "v" label, which here is "Backlog"?
Note that the number of labels varies from issue to issue. The ::
signifies that a label is a scoped label.
Upvotes: 0
Views: 79
Reputation: 265747
A trivial and straightforward solution with startswith
and substring/string-slicing:
.labels[] | select(startswith("v::"))[3:]
If you need it to be more dynamic:
jq --arg scope 'v::' '.labels[] | select(startswith($scope))[$scope|length:]'
Upvotes: 0
Reputation: 26727
You can use scan
(or capture
) :
#!/bin/bash
echo '{"labels": [
"AI::Assessed",
"Pri::1 - High",
"Type::Investigation",
"v::Backlog"
]}' | jq -r '.labels[] | scan("v::(.*)")[]'
# Output : Backlog
Upvotes: 0