I’m trying to extract info on certain specific dependencies from the output of DTrack’s /v1/project
endpoint.
The API returns data in the format:
[{
"name": "project name",
"directDependencies": <escaped JSON string in which I need to search for "com.example.commons/[email protected]" and similar strings>
}, ...]
Here’s what I got so far:
jq '.[] | select(.classifier=="APPLICATION") | {
id: .name,
dep1: ((.directDependencies // "") | capture(["com\.example\.commons/dep1@(?<version>[0-9.]+)"])),
dep2: ((.directDependencies // "") | capture(["com\.example\.commons/dep2@(?<version>[0-9.]+)"])),
dep3: ((.directDependencies // "") | capture(["com\.example\.commons/dep3@(?<version>[0-9.]+)"])),
dep4: ((.directDependencies // "") | capture(["com\.example\.commons/dep4@(?<version>[0-9.]+)"]))
}'
Generated output looks fine:
{
"id": "project1",
"dep1": {
"version": "0.102.0"
},
"dep2": {
"version": "0.102.0"
},
"dep3": {
"version": "0.102.0"
},
"dep4": {
"version": "0.102.0"
}
}
... // more elements
The problem is, the output only contains those of the input elements for which all four capture
s matched something.
I would like the output to contain all the elements of the input list, even if some of the capture
s fail to match. In other words, I would expect elements in the output like:
{
"id": "project1",
"dep1": { "version": "0.1.0" },
// dep2 didn't match
// dep3 didn't match
"dep4": { "version": "0.3.0" }
}
I couldn’t find such an option in the docs. Any ideas how to solve this?