title: How to nicely remove empty array in jq
body: <p>I am reading O'Reilly's new "Data Science at the Command Line" and running into trouble using jq. I have some JSON (returned from the NYTimes Articles API) I am parsing with jq like so:</p>
  
  <pre><code>jq -c \
  '[.response.docs[] | {date: .pub_date, type: .document_type, title: .headline.main }]' \
  &lt; myjsonfile.json
  </code></pre>
  
  <p>So, I am looking for "response":"docs" (which is an array) and then matching every item in that array with "pub_type" etc., renaming it, and so on. This works great, but it adds an empty array at the end:</p>
  
  <pre><code>[{"date":"2009-01-02T00:00:00Z","type":"article","title":"SPARE TIMES: AROUND TOWN"},  
  {"date":"2009-01-02T00:00:00Z","type":"article","title":"Catskill Home Prices: How Low Will They Go?"},
  {"date":"2009-01-01T00:00:00Z","type":"article","title":"Ominous Cutbacks At Chanel"}]
  [] 
  </code></pre>
  
  <p>How do I get rid of the empty array? My solution right now is to pipe the output back into jq, but that feels really suboptimal. So this works:</p>
  
  <pre><code>jq -c \
  '[.response.docs[] | {date: .pub_date, type: .document_type, title: .headline.main }]' | \
  &lt; myjsonfile.json | 
  jq 'if length &gt; 0 then . else empty end'
  </code></pre>
  
  <p>But that feels ugly. Is there a nicer way of doing this?</p>