‘jq’ support comparison operators to process json data.
compOperators.json
{
"1": {
"org": [{
"name": "ABC Cord",
"yrsOfExperience": 2.2
}, {
"name": "XYZ",
"yrsOfExperience": 1.8
}],
"firstName": "Krishna",
"lastName": "Ram",
"address": {
"city": "Bangalore",
"country": "India"
}
},
"2": {
"org": [{
"name": "XYZ",
"yrsOfExperience": 4.2
}, {
"name": "Bokara",
"yrsOfExperience": 3.8
}],
"firstName": "Battu",
"lastName": "Gopi",
"address": {
"city": "Bangalore",
"country": "India"
}
},
"3": {
"org": [{
"name": "Dongle",
"yrsOfExperience": 2.6
}, {
"name": "Binare",
"yrsOfExperience": 1.11
}],
"firstName": "Krishna",
"lastName": "Ram",
"address": {
"city": "Hyderabad",
"country": "India"
}
}
}
Example 1: Get all the employees who are working in Bangalore.
$cat compOperators.json | jq '.[] | select(.address.city=="Bangalore") | .firstName+","+.lastName'
"Krishna,Ram"
"Battu,Gopi"
Previous Next Home
No comments:
Post a Comment