title: How do I collect unique elements of an array-valued field across multiple objects in jq?
body: <p>I have json data that looks like:</p>
  
  <pre><code>{"foo":"one", "bar":2, "baz":[0]}
  {"foo":"two", "bar":3, "baz":[1]}
  {"foo":"one", "bar":3, "baz":[2,3]}
  {"foo":"one", "bar":2, "baz":[2,4]}
  </code></pre>
  
  <p>I want to group everything with the same "foo" and collect the unique values of bar, and then collect the unique values inside of the "baz" arrays:</p>
  
  <pre><code>[
    {"foo":"one", "bar":[2, 3], "baz":[0,2,3,4]},
    {"foo":"two", "bar":[3], "baz":[1]}
  ]
  </code></pre>
  
  <p>(I don't care if the result is in an array or just a raw sequence of whitespace separated JSON objects, and I don't care about the order of the items in the "baz" array)</p>
  
  <p>I've got jq version 1.4 installed from source.  I can properly group by "foo" and collect unique values of "bar" with:</p>
  
  <pre><code>jq -s 'group_by(.foo) | map({foo: .[0].foo, bar: map(.bar) | unique})'
  </code></pre>
  
  <p>yielding:</p>
  
  <pre><code>[
    {"foo":"one","bar":[2,3]},
    {"foo":"two","bar":[3]}
  ]
  </code></pre>
  
  <p>but I can't figure out how to do the collection of unique values of "baz".</p>
  
  <p>What am I missing?  </p>