title: Generate new array from sparse array of objects in JQ
body: <p>I have a JSON file that I want to process with JQ. It has an array of objects inside another object, with a key that I want to use to populate a new array.</p>
  
  <p>In my real use-case this is nested in with a lot of other fluff and there lots more arrays but take this as a simpler but representative example of the kind of thing:</p>
  
  <pre><code>{
    "numbers": [
      {
        "numeral": 1,
        "ordinal": "1st",
        "word": "One"
      },
      {
        "numeral": 2,
        "ordinal": "2nd",
        "word": "Two"
      },
      {
        "numeral": 5,
        "ordinal": "5th",
        "word": "Five"
      },
      {
        "some-other-fluff-i-want-to-ignore": true
      }
    ]
  }
  </code></pre>
  
  <p>I'd like to use JQ to get a new array based on the elements, ignoring some elements and handling the missing ones. e.g.</p>
  
  <pre><code>[
    "The 1st word is One",
    "The 2nd word is Two",
    "Wot no number 3?",
    "Wot no number 4?",
    "The 5th word is Five"
  ]
  </code></pre>
  
  <p>Doing this in a loop for the elements that are there is simple, terse and elegant enough:</p>
  
  <pre><code>.numbers | map( . | select( .numeral) | [ "The", .ordinal, "word is", .word ] | join (" "))
  </code></pre>
  
  <p>But I can't find a way to cope with the missing entries. I have some code that sort-of works:</p>
  
  <pre><code>.numbers | [
    ( .[] | select(.numeral == 1) | ( [ "The", .ordinal, "word is", .word ] | join (" ")) ) // "Wot no number 1?",
    ( .[] | select(.numeral == 2) | ( [ "The", .ordinal, "word is", .word ] | join (" ")) ) // "Wot no number 2?",
    ( .[] | select(.numeral == 3) | ( [ "The", .ordinal, "word is", .word ] | join (" ")) ) // "Wot no number 3?",
    ( .[] | select(.numeral == 4) | ( [ "The", .ordinal, "word is", .word ] | join (" ")) ) // "Wot no number 4?",
    ( .[] | select(.numeral == 5) | ( [ "The", .ordinal, "word is", .word ] | join (" ")) ) // "Wot no number 5?"
  ]
  </code></pre>
  
  <p>It produces usable output, after a fashion:</p>
  
  <pre><code>richard@sophia:~$ jq -f make-array.jq &lt; numbers.json
  [
    "The 1st word is One",
    "The 2nd word is Two",
    "Wot no number 3?",
    "Wot no number 4?",
    "The 5th word is Five"
  ]
  richard@sophia:~$ 
  </code></pre>
  
  <p>However, whilst it produces the output, handles the missing elements and ignores the bits I don't want, it's obviously extremely naff code that cries out for a for-loop or something similar but I can't see a way in JQ to do this. Any ideas?</p>