title: How to extract keys from multiple, nested arrays using jq
body: <p><strong>SETUP</strong></p>
  
  <p>I'm trying to figure out how jq filters work and having trouble figuring out nested arrays. Using the data below I cannot make a flat 5 key output. I can get 1 key and 4 nulls or 4 keys and 1 null, but not all 5 keys.</p>
  
  <p>1 key, 4 nulls:</p>
  
  <pre><code>.Reservations[] | {OwnerId, InstanceId, ImageId, PrivateIpAddress, Platform}
  </code></pre>
  
  <p>Returns:</p>
  
  <pre><code>{
   "OwnerId": "000000000000",
   "InstanceId": null,
   "ImageId": null,
   "PrivateIpAddress": null,
   "Platform": null
  }
  </code></pre>
  
  <p>4 keys, 1 null:</p>
  
  <pre><code>.Reservations[].Instances[] | {OwnerId, InstanceId, ImageId, PrivateIpAddress, Platform}
  
  {
    "OwnerId": null,
    "InstanceId": "i-v33333333",
    "ImageId": "ami-44444444",
    "PrivateIpAddress": "10.0.0.0",
    "Platform": "windows"
  }
  </code></pre>
  
  <p>For a various reasons I cannot use the "--query" option in AWS CLI which does return the format I'm looking for:</p>
  
  <pre><code>aws ec2 describe-instances --region us-east-1 --profile temp --query 'Reservations[*].{InstanceId:Instances[0].InstanceId,IP:Instances[0].PrivateIpAddress,Platform:Instances[0].Platform,OwnerId:OwnerId}'
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>[
      {
          "InstanceId": "i-11111111",
          "IP": "10.9.9.3",
          "OwnerId": "111111111111",
          "Platform": windows
      },
      {
          "InstanceId": "i-22222222",
          "IP": "10.0.0.0",
          "OwnerId": "111111111111",
          "Platform": windows
      }
  ]
  </code></pre>
  
  <p>Here is the JSON input:</p>
  
  <pre><code>   {
      "Reservations": [
          {
              "OwnerId": "000000000000",
              "ReservationId": "r-22222222",
              "Groups": [],
              "RequesterId": "111111111111",
              "Instances": [
                  {
                      "Monitoring": {
                          "State": "enabled"
                      },
                      "PublicDnsName": null,
                      "State": {
                          "Code": 16,
                          "Name": "running"
                      },
                      "EbsOptimized": false,
                      "LaunchTime": "2015-04-10T00:02:02.000Z",
                      "Platform": "windows",
                      "PrivateIpAddress": "10.0.0.0",
                      "ProductCodes": [
                          {
                              "ProductCodeId": "0000000000000000000000000",
                              "ProductCodeType": "marketplace"
                          }
                      ],
                      "VpcId": "vpc-2222222",
                      "StateTransitionReason": null,
                      "InstanceId": "i-v33333333",
                      "ImageId": "ami-44444444",
                      "PrivateDnsName": "ip-10-0-0-0.aws.foobarcloud.com",
                      "KeyName": "bar-servicemesh",
                      "SecurityGroups": [
                          {
                              "GroupName": "bar-wildcard-dns-intranet-InstanceSecurityGroup-VN0DFQ13QCDY",
                              "GroupId": "sg-55555555"
                          }
                      ],
                      "ClientToken": "11111111-2222-3333-4444-555555555555_subnet-66666666_1",
                      "SubnetId": "subnet-66666666",
                      "InstanceType": "t2.medium",
                      "NetworkInterfaces": [
                          {
                              "Status": "in-use",
                              "MacAddress": "00:00:00:00:00:77",
                              "SourceDestCheck": true,
                              "VpcId": "vpc-66666666",
                              "Description": null,
                              "NetworkInterfaceId": "eni-11111111"
                          }
                      ]
                  }
              ]
          }
      ]
  }
  </code></pre>
  
  <p><strong>QUESTION</strong>
  Using the JSON input above, how do you use jq to produce the following output?:</p>
  
  <pre><code>{
    "OwnerId": "000000000000",
    "InstanceId": "i-v33333333",
    "ImageId": "ami-44444444",
    "PrivateIpAddress": "10.0.0.0",
    "Platform": "windows"
  }
  </code></pre>