Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

jq: . : Access value of specific property

Using . operator, we can access specific value of a Property.

 

empPretty.json 

{
"org": [{
"name": "Honeywell",
"yrsOfExperience": 2.2
}, {
"name": "IBM",
"yrsOfExperience": 1.8
}],
"firstName": "Krishna",
"lastName": "Ram",
"address": {
"city": "Bangalore",
"country": "India"
}
}

 

.org: access the value of org property

.firstName: access the value of firstName property

.lastName: access the value of lastName property

.address.city access the value of city property.

 

$cat empPretty.json | jq '.org'
[
{
"name": "Honeywell",
"yrsOfExperience": 2.2
},
{
"name": "IBM",
"yrsOfExperience": 1.8
}
]
$
$
$cat empPretty.json | jq '.firstName'
"Krishna"
$
$cat empPretty.json | jq '.lastName'
"Ram"
$
$cat empPretty.json | jq '.address.city'
"Bangalore"

 

Access multiple properties in single command

Using , operator, you can access multiple properties in single command.

 

Example

$cat empPretty.json | jq '.firstName, .lastName'
"Krishna"
"Ram"

Above command extract firstName and lastName properties.

$cat empPretty.json | jq '.org[].name, .org[].yrsOfExperience'
"Honeywell"
"IBM"
2.2
1.8


Above command extract organization name and yrsOfExperience of an employee.



Previous                                                    Next                                                    Home


This post first appeared on Java Tutorial : Blog To Learn Java Programming, please read the originial post: here

Share the post

jq: . : Access value of specific property

×

Subscribe to Java Tutorial : Blog To Learn Java Programming

Get updates delivered right to your inbox!

Thank you for your subscription

×