I am new to jq and I have a scenario to get the parent(at a particular level) of any matching value in the json file. Below is the sample data.
{
"DevOps": {
"us-east-1": {
"i-049aa9a3bddb4****": {
"AmiLaunchIndex": 0,
"ImageId": "ami-00068cd7555f543d5",
"InstanceId": "i-049aa9a3bddb4*****",
"InstanceType": "t2.nano",
"LaunchTime": "2019-11-24 18:39:25+00:00",
"Monitoring": {
"State": "disabled"
},
"Placement": {
"AvailabilityZone": "us-east-1a",
"GroupName": "",
"Tenancy": "default"
},
"PrivateDnsName": "ip-10-250-128-77.ec2.internal",
"PrivateIpAddress": "10.250.128.77",
"ProductCodes": [],
"PublicDnsName": "",
"Tags": [
{
"Key": "Name",
"Value": "Network-Test-Host"
}
],
},
"i-0368117434*****": {
"AmiLaunchIndex": 0,
"ImageId": "ami-078137ecf12552edf",
"InstanceId": "i-0368117434******",
"InstanceType": "c5.2xlarge",
"KeyName": "infra-systems-prod-key",
"LaunchTime": "2020-02-13 15:51:15+00:00",
"Monitoring": {
"State": "disabled"
},
"Placement": {
"AvailabilityZone": "us-east-1a",
"GroupName": "",
"Tenancy": "default"
},
"PrivateDnsName": "ip-10-250-138-161.ec2.internal",
"PrivateIpAddress": "10.250.138.161",
"ProductCodes": [],
"PublicDnsName": "",
"Tags": [
{
"Key": "Name",
"Value": "Network-Test-Host"
}
],
},
}
}
}
For example, if my search value is "10.250.128.77", it should fetch the parent - "i-049aa9a3bddb4****". if the value is "Network-Test-Host", it should give me the list of 2 instance ids(i-049aa9a3bddb4****, i-0368117434*****). Then from this point, I would be able to traverse at any key and get the respective value like the hostname, ImageId, Instance Type
Any help on this is much appreciated