title: Yq: retrieve object keys names
body: <p>I have a YAML file (docker-compose file in my case) that looks like this:</p>
  
  <pre><code>networks:
      foo:
        some_opts: "covfefe"
      bar:
        some_opts: "such wow"
  services:
    apache:
      image: 'apache:1.0.0'
      restart: always
    mysql:
      image: 'mysql:1.0.0'
      restart: always
    php:
      image: 'php'
      restart: always
  </code></pre>
  
  <p>I would like to extract the services name thanks to <a href="https://github.com/kislyuk/yq" rel="nofollow noreferrer"><code>yq</code></a>, an equivalent of <code>jq</code> but for YAML, to have this output:</p>
  
  <pre><code>"apache"
  "mysql"
  "php"
  </code></pre>
  
  <p>Currently I can achieve it like this:</p>
  
  <pre><code>$ cat docker-compose.yml | yq '.services' | yq 'keys[]'
  "apache"
  "mysql"
  "php"
  </code></pre>
  
  <p>Even if it works, the double piped <code>yq</code> seems weird to me. I think I'm doing it wrong. </p>
  
  <p><strong>Question:</strong> Is there any way to achieve it with a single <code>yq</code> command ?</p>
  
  <p>I tried this without success, taking inspiration from <a href="https://stackoverflow.com/questions/23118341/how-to-get-key-names-from-json-using-jq">this question</a>:</p>
  
  <pre><code>$ cat docker-compose.yml | yq '.services.keys[]'
  jq: error: Cannot iterate over null
  </code></pre>