I have JSONPath:
$.endpointAgents[?(@.clients.userName=~ 'a')].agentId
How it will look in jq format on Linux??
jq '.endpointAgents [] | select(.clients.userName=~"a") | {agentId}')"
does not work.
Code:
{ "endpointAgents":[
{
"agentId": "MyId",
"agentName": "MYNAME",
"location": {
"locationName": "location"
},
"clients": [
{
"userProfile": {
"userName": "Name"
},
"browserExtensions": [
{
"active": false
}
]
},
],
"totalMemory": "16222 MB",
"agentType": "enterprise"
}```
CodePudding user response:
I want to get userName value by specifying agentId
jq '.endpointAgents[] | select(.agentId == "MyId") | .clients[].userProfile.userName'
Will output "Name"
.endpointAgents[]
Loop over eachendpointAgentselect(.agentId == "MyId")
Select the objects where.agentId == "MyId".clients[].userProfile.userName
Sinceclientsis an array, loop over it, and show.userProfile.userNamefor each object.
