jq
Selecting JSON Properties
Property Name Contains Dashes
{
"first-name": "john",
"last-name": "doe",
"nickname": "jim"
}
file.json
jq ."first-name" < file.json
Incorrect
jq '."first-name"' < file.json
Correct
Select a Property from an Array of Objects
users.json (sample data)
[{
"attributes": {
"accountExpires": [
"1601-01-01 00:00:00+00:00"
],
"badPasswordTime": [
"1601-01-01 00:00:00+00:00"
],
"badPwdCount": [
0
],
"cn": [
"jim"
],
"codePage": [
0
],
"countryCode": [
0
],
"dSCorePropagationData": [
"2025-06-09 20:52:09+00:00",
"2025-06-09 20:52:09+00:00",
"2025-06-09 20:52:08+00:00",
"2025-06-09 20:52:07+00:00",
"1601-01-01 00:00:00+00:00"
],
"distinguishedName": [
"CN=jim,CN=Users,DC=activedirectory,DC=lab"
],
"givenName": [
"jim"
],
"instanceType": [
4
],
"lastLogoff": [
"1601-01-01 00:00:00+00:00"
],
"lastLogon": [
"1601-01-01 00:00:00+00:00"
],
"lastLogonTimestamp": [
"2025-06-04 23:07:24.375269+00:00"
],
"logonCount": [
0
],
"logonHours": [
{
"encoded": "////////////////////////////",
"encoding": "base64"
}
],
"memberOf": [
"CN=Remote Management Users,CN=Builtin,DC=activedirectory,DC=lab"
],
"name": [
"jim"
],
"objectCategory": [
"CN=Person,CN=Schema,CN=Configuration,DC=activedirectory,DC=lab"
],
"objectClass": [
"top",
"person",
"organizationalPerson",
"user"
],
"objectGUID": [
"{0170746d-3f8c-4f60-b3a5-3e517d686db9}"
],
"objectSid": [
"S-1-5-21-1392491010-1358638721-2126982587-1106"
],
"primaryGroupID": [
513
],
"pwdLastSet": [
"2025-05-19 13:25:10.754210+00:00"
],
"sAMAccountName": [
"jim"
],
"sAMAccountType": [
805306368
],
"sn": [
"jim"
],
"uSNChanged": [
94311
],
"uSNCreated": [
12808
],
"userAccountControl": [
66048
],
"whenChanged": [
"2025-06-09 20:52:09+00:00"
],
"whenCreated": [
"2024-11-16 00:54:13+00:00"
]
},
"dn": "CN=jim,CN=Users,DC=activedirectory,DC=lab"
},{
"attributes": {
"accountExpires": [
"1601-01-01 00:00:00+00:00"
],
"badPasswordTime": [
"1601-01-01 00:00:00+00:00"
],
"badPwdCount": [
0
],
"cn": [
"tom"
],
"codePage": [
0
],
"countryCode": [
0
],
"dSCorePropagationData": [
"2024-11-16 17:06:24+00:00",
"2024-11-16 17:04:51+00:00",
"2024-11-16 17:00:02+00:00",
"2024-11-16 16:58:29+00:00",
"1601-01-01 00:00:00+00:00"
],
"distinguishedName": [
"CN=tom,CN=Users,DC=activedirectory,DC=lab"
],
"givenName": [
"tom"
],
"instanceType": [
4
],
"lastLogoff": [
"1601-01-01 00:00:00+00:00"
],
"lastLogon": [
"1601-01-01 00:00:00+00:00"
],
"logonCount": [
0
],
"logonHours": [
{
"encoded": "////////////////////////////",
"encoding": "base64"
}
],
"name": [
"tom"
],
"objectCategory": [
"CN=Person,CN=Schema,CN=Configuration,DC=activedirectory,DC=lab"
],
"objectClass": [
"top",
"person",
"organizationalPerson",
"user"
],
"objectGUID": [
"{453ed19c-698e-4914-becd-721df607d43a}"
],
"objectSid": [
"S-1-5-21-1392491010-1358638721-2126982587-1105"
],
"primaryGroupID": [
513
],
"pwdLastSet": [
"2025-05-12 15:17:03.386223+00:00"
],
"sAMAccountName": [
"tom"
],
"sAMAccountType": [
805306368
],
"sn": [
"tom"
],
"uSNChanged": [
36903
],
"uSNCreated": [
12802
],
"userAccountControl": [
66048
],
"whenChanged": [
"2025-05-12 15:17:03+00:00"
],
"whenCreated": [
"2024-11-16 00:54:13+00:00"
]
},
"dn": "CN=tom,CN=Users,DC=activedirectory,DC=lab"
},{
"attributes": {
"accountExpires": [
"1601-01-01 00:00:00+00:00"
],
"badPasswordTime": [
"1601-01-01 00:00:00+00:00"
],
"badPwdCount": [
0
],
"cn": [
"Jenkins"
],
"codePage": [
0
],
"countryCode": [
0
],
"dSCorePropagationData": [
"2024-11-16 17:06:24+00:00",
"2024-11-16 17:04:51+00:00",
"2024-11-16 17:00:02+00:00",
"2024-11-16 16:58:29+00:00",
"1601-01-01 00:00:00+00:00"
],
"distinguishedName": [
"CN=Jenkins,CN=Users,DC=activedirectory,DC=lab"
],
"givenName": [
"Jenkins"
],
"instanceType": [
4
],
"lastLogoff": [
"1601-01-01 00:00:00+00:00"
],
"lastLogon": [
"1601-01-01 00:00:00+00:00"
],
"logonCount": [
0
],
"logonHours": [
{
"encoded": "////////////////////////////",
"encoding": "base64"
}
],
"name": [
"Jenkins"
],
"objectCategory": [
"CN=Person,CN=Schema,CN=Configuration,DC=activedirectory,DC=lab"
],
"objectClass": [
"top",
"person",
"organizationalPerson",
"user"
],
"objectGUID": [
"{0c3dc10f-30e7-4047-9201-f35df3bb8939}"
],
"objectSid": [
"S-1-5-21-1392491010-1358638721-2126982587-1104"
],
"primaryGroupID": [
513
],
"pwdLastSet": [
"2025-05-12 15:17:03.526670+00:00"
],
"sAMAccountName": [
"Jenkins"
],
"sAMAccountType": [
805306368
],
"sn": [
"Jenkins"
],
"uSNChanged": [
36907
],
"uSNCreated": [
12796
],
"userAccountControl": [
66048
],
"whenChanged": [
"2025-05-12 15:17:03+00:00"
],
"whenCreated": [
"2024-11-16 00:54:13+00:00"
]
},
"dn": "CN=Jenkins,CN=Users,DC=activedirectory,DC=lab"
},{
"attributes": {
"accountExpires": [
"1601-01-01 00:00:00+00:00"
],
"badPasswordTime": [
"1601-01-01 00:00:00+00:00"
],
"badPwdCount": [
0
],
"cn": [
"Henry"
],
"codePage": [
0
],
"countryCode": [
0
],
"dSCorePropagationData": [
"2024-11-16 17:04:51+00:00",
"2024-11-16 16:58:29+00:00",
"1601-01-01 00:00:00+00:00"
],
"distinguishedName": [
"CN=Henry,CN=Users,DC=activedirectory,DC=lab"
],
"givenName": [
"Henry"
],
"instanceType": [
4
],
"lastLogoff": [
"1601-01-01 00:00:00+00:00"
],
"lastLogon": [
"1601-01-01 00:00:00+00:00"
],
"lastLogonTimestamp": [
"2025-06-09 20:52:19.605484+00:00"
],
"logonCount": [
0
],
"logonHours": [
{
"encoded": "////////////////////////////",
"encoding": "base64"
}
],
"name": [
"Henry"
],
"objectCategory": [
"CN=Person,CN=Schema,CN=Configuration,DC=activedirectory,DC=lab"
],
"objectClass": [
"top",
"person",
"organizationalPerson",
"user"
],
"objectGUID": [
"{b8e8a0b3-215f-43e7-8762-bc4a552b1511}"
],
"objectSid": [
"S-1-5-21-1392491010-1358638721-2126982587-1103"
],
"primaryGroupID": [
513
],
"pwdLastSet": [
"2025-05-12 15:17:03.589167+00:00"
],
"sAMAccountName": [
"Henry"
],
"sAMAccountType": [
805306368
],
"sn": [
"Henry"
],
"uSNChanged": [
94313
],
"uSNCreated": [
12790
],
"userAccountControl": [
66048
],
"whenChanged": [
"2025-06-09 20:52:19+00:00"
],
"whenCreated": [
"2024-11-16 00:54:13+00:00"
]
},
"dn": "CN=Henry,CN=Users,DC=activedirectory,DC=lab"
},{
"attributes": {
"accountExpires": [
"9999-12-31 23:59:59.999999+00:00"
],
"adminCount": [
1
],
"badPasswordTime": [
"1601-01-01 00:00:00+00:00"
],
"badPwdCount": [
0
],
"cn": [
"krbtgt"
],
"codePage": [
0
],
"countryCode": [
0
],
"dSCorePropagationData": [
"2024-11-16 17:04:51+00:00",
"2024-11-16 16:58:29+00:00",
"2024-11-16 00:54:13+00:00",
"2024-11-16 00:17:38+00:00",
"1601-01-01 00:00:00+00:00"
],
"description": [
"Key Distribution Center Service Account"
],
"distinguishedName": [
"CN=krbtgt,CN=Users,DC=activedirectory,DC=lab"
],
"instanceType": [
4
],
"isCriticalSystemObject": [
true
],
"lastLogoff": [
"1601-01-01 00:00:00+00:00"
],
"lastLogon": [
"1601-01-01 00:00:00+00:00"
],
"logonCount": [
0
],
"memberOf": [
"CN=Denied RODC Password Replication Group,CN=Users,DC=activedirectory,DC=lab"
],
"msDS-SupportedEncryptionTypes": [
0
],
"name": [
"krbtgt"
],
"objectCategory": [
"CN=Person,CN=Schema,CN=Configuration,DC=activedirectory,DC=lab"
],
"objectClass": [
"top",
"person",
"organizationalPerson",
"user"
],
"objectGUID": [
"{704030f8-531c-49f2-8bf0-ddb1c0bb57e0}"
],
"objectSid": [
"S-1-5-21-1392491010-1358638721-2126982587-502"
],
"primaryGroupID": [
513
],
"pwdLastSet": [
"2024-11-16 00:02:28.644709+00:00"
],
"sAMAccountName": [
"krbtgt"
],
"sAMAccountType": [
805306368
],
"servicePrincipalName": [
"kadmin/changepw"
],
"showInAdvancedViewOnly": [
true
],
"uSNChanged": [
12775
],
"uSNCreated": [
12324
],
"userAccountControl": [
514
],
"whenChanged": [
"2024-11-16 00:17:38+00:00"
],
"whenCreated": [
"2024-11-16 00:02:28+00:00"
]
},
"dn": "CN=krbtgt,CN=Users,DC=activedirectory,DC=lab"
},{
"attributes": {
"accountExpires": [
"9999-12-31 23:59:59.999999+00:00"
],
"badPasswordTime": [
"1601-01-01 00:00:00+00:00"
],
"badPwdCount": [
0
],
"cn": [
"Guest"
],
"codePage": [
0
],
"countryCode": [
0
],
"dSCorePropagationData": [
"2024-11-16 17:04:51+00:00",
"2024-11-16 16:58:29+00:00",
"2024-11-16 00:54:13+00:00",
"2024-11-16 00:02:28+00:00",
"1601-07-14 22:32:32+00:00"
],
"description": [
"Built-in account for guest access to the computer/domain"
],
"distinguishedName": [
"CN=Guest,CN=Users,DC=activedirectory,DC=lab"
],
"instanceType": [
4
],
"isCriticalSystemObject": [
true
],
"lastLogoff": [
"1601-01-01 00:00:00+00:00"
],
"lastLogon": [
"1601-01-01 00:00:00+00:00"
],
"logonCount": [
0
],
"memberOf": [
"CN=Guests,CN=Builtin,DC=activedirectory,DC=lab"
],
"name": [
"Guest"
],
"objectCategory": [
"CN=Person,CN=Schema,CN=Configuration,DC=activedirectory,DC=lab"
],
"objectClass": [
"top",
"person",
"organizationalPerson",
"user"
],
"objectGUID": [
"{70fba64f-d33d-4117-bfd0-65e69f9ebe27}"
],
"objectSid": [
"S-1-5-21-1392491010-1358638721-2126982587-501"
],
"primaryGroupID": [
514
],
"pwdLastSet": [
"1601-01-01 00:00:00+00:00"
],
"sAMAccountName": [
"Guest"
],
"sAMAccountType": [
805306368
],
"uSNChanged": [
8197
],
"uSNCreated": [
8197
],
"userAccountControl": [
66082
],
"whenChanged": [
"2024-11-16 00:01:41+00:00"
],
"whenCreated": [
"2024-11-16 00:01:41+00:00"
]
},
"dn": "CN=Guest,CN=Users,DC=activedirectory,DC=lab"
},{
"attributes": {
"accountExpires": [
"1601-01-01 00:00:00+00:00"
],
"adminCount": [
1
],
"badPasswordTime": [
"2024-11-15 23:56:52.722843+00:00"
],
"badPwdCount": [
0
],
"cn": [
"Administrator"
],
"codePage": [
0
],
"countryCode": [
0
],
"dSCorePropagationData": [
"2024-11-16 17:04:51+00:00",
"2024-11-16 16:58:29+00:00",
"2024-11-16 00:54:13+00:00",
"2024-11-16 00:17:38+00:00",
"1601-01-01 00:00:00+00:00"
],
"description": [
"Built-in account for administering the computer/domain"
],
"distinguishedName": [
"CN=Administrator,CN=Users,DC=activedirectory,DC=lab"
],
"instanceType": [
4
],
"isCriticalSystemObject": [
true
],
"lastLogoff": [
"1601-01-01 00:00:00+00:00"
],
"lastLogon": [
"2025-06-09 20:41:18.449268+00:00"
],
"lastLogonTimestamp": [
"2025-06-04 19:18:55.164364+00:00"
],
"logonCount": [
57
],
"logonHours": [
{
"encoded": "////////////////////////////",
"encoding": "base64"
}
],
"memberOf": [
"CN=Group Policy Creator Owners,CN=Users,DC=activedirectory,DC=lab",
"CN=Domain Admins,CN=Users,DC=activedirectory,DC=lab",
"CN=Enterprise Admins,CN=Users,DC=activedirectory,DC=lab",
"CN=Schema Admins,CN=Users,DC=activedirectory,DC=lab",
"CN=Users,CN=Builtin,DC=activedirectory,DC=lab",
"CN=Administrators,CN=Builtin,DC=activedirectory,DC=lab"
],
"name": [
"Administrator"
],
"objectCategory": [
"CN=Person,CN=Schema,CN=Configuration,DC=activedirectory,DC=lab"
],
"objectClass": [
"top",
"person",
"organizationalPerson",
"user"
],
"objectGUID": [
"{80705833-9740-4674-85ba-2daee229c632}"
],
"objectSid": [
"S-1-5-21-1392491010-1358638721-2126982587-500"
],
"primaryGroupID": [
513
],
"pwdLastSet": [
"2025-04-25 14:56:03.823982+00:00"
],
"sAMAccountName": [
"Administrator"
],
"sAMAccountType": [
805306368
],
"uSNChanged": [
65582
],
"uSNCreated": [
8196
],
"userAccountControl": [
66048
],
"whenChanged": [
"2025-06-04 19:18:55+00:00"
],
"whenCreated": [
"2024-11-16 00:01:41+00:00"
]
},
"dn": "CN=Administrator,CN=Users,DC=activedirectory,DC=lab"
}]
jq '.[].attributes.sAMAccountName[]' < users.json
.[] indicates we're processing an array of objects, selecting .attributes and selecting the nested .sAMAccountName[] array of each object
If you inspect the sample data, the sAMAccountName attribute is an array, so we use the sAMAccountName[] syntax to flatten the array. If you want to remove the " double quotes from the output, use jq -r to output the raw data.jq -r '.[].attributes.sAMAccountName[]' < users.json
Select Multiple Properties
wp-json users
[
{
"id": 1,
"name": "admin",
"url": "http://127.0.0.1",
"description": "",
"link": "http://localhost/author/user/",
"slug": "user",
"avatar_urls": {
"24": "https://secure.gravatar.com/avatar/b4c9a289323b21a01c3e940f150eb9b8c542587f1abfd8f0e1cc1ffc5e475514?s=24&d=mm&r=g",
"48": "https://secure.gravatar.com/avatar/b4c9a289323b21a01c3e940f150eb9b8c542587f1abfd8f0e1cc1ffc5e475514?s=48&d=mm&r=g",
"96": "https://secure.gravatar.com/avatar/b4c9a289323b21a01c3e940f150eb9b8c542587f1abfd8f0e1cc1ffc5e475514?s=96&d=mm&r=g"
},
"meta": {
"marketing_optin": ""
},
"_links": {
"self": [
{
"href": "http://localhostlocalhost/wp-json/wp/v2/users/1",
"targetHints": {
"allow": [
"GET"
]
}
}
],
"collection": [
{
"href": "http://localhost/wp-json/wp/v2/users"
}
]
}
}
]
jq 'map({id,name,url})' < data.json
Minify JSON
jq -c . /tmp/data.json
Removes all new lines and whitespace from object notation


