title: PostgreSQL single-column table to JSON array
body: <p>I have a query like this:</p>
  
  <pre><code>SELECT DISTINCT floor FROM rooms WHERE building_id = 23;
  </code></pre>
  
  <p>I want to convert the result into a JSON array. I was able to use <code>json_agg()</code> as follows:</p>
  
  <pre><code>SELECT json_agg(a) from (SELECT DISTINCT floor FROM rooms WHERE building_id = 23) as a;
  </code></pre>
  
  <p>But that results in an array of key/value pairs:</p>
  
  <pre><code>[{"floor":null},{"floor":1},{"floor":4},{"floor":2},{"floor":0},{"floor":3}]
  </code></pre>
  
  <p>When really I want an array of just the values:</p>
  
  <pre><code>[null,1,4,2,0,3]
  </code></pre>
  
  <p>For performance and bandwidth reasons, I don't want to have the column name repeated unnecessarily. Any ideas on how to make a JSON array of just the values?</p>
  
  <p>(I also tried <code>array_to_json(array_agg())</code>, but that produced the same results as <code>json_agg()</code>)</p>