title: Building JSON from Postgres rows without column names
body: <p>I have a 3 colum PostgreSQL 9.4.4 tbl where k:TEXT, UNIQUE, v:INT, t:TEXT.</p>
  
  <pre><code>k      v      t
  ----------------
  k1     3      x
  k6     5      x
  k11    3      y
  k3     2      z
  k4     2      y
  k7     1      x
  ..     .      .
  </code></pre>
  
  <p>I'm trying to auto-generate 3 JSON arrays, seperately:</p>
  
  <pre><code>1. [{"k1":3},{"k6":5},{"k7":1}] (WHERE t=x)
  2. [{"k11":3},{"k4":2}] (WHERE t=y)
  3. [{"k3":2}] (WHERE t=z)
  </code></pre>
  
  <p>QUESTIONS:</p>
  
  <ol>
  <li>First, </li>
  </ol>
  
  <blockquote>
    <p>SELECT JSON_BUILD_OBJECT(k,v) FROM tbl</p>
  </blockquote>
  
  <p>gives me individual json elements {"k1":3},{"k6":5}, etc. 
  I can build full json array in my app (in Go), but it's hacky. 
  How do I get the full [{"k1":3},{"k6":5},{"k7":1}]?</p>
  
  <blockquote>
    <p>SELECT array_to_json(array_agg(row_to_json(tx))) FROM (SELECT k,v FROM
    tbl ) tx;</p>
  </blockquote>
  
  <p>gives me column names, which I don't want: 
  [{"k":"k1","v":3},{"k":"k6","v":5} etc. I need [{"k1":3},{"k6":5}, etc</p>
  
  <ol start="2">
  <li>Also, </li>
  </ol>
  
  <blockquote>
    <p>SELECT JSON_BUILD_OBJECT(k,v) FROM tbl WHERE t=x;</p>
  </blockquote>
  
  <p>errors so I can't filter on t. I don't want GROUP BY, I want to generate 3 different json arrays separately, on 3 different passes, depending on the value of WHERE t=. IOW, I don't want [{"y":[{"k11":3},{"k4":2}], etc</p>
  
  <p>I am new to json ops in Postgres 9.4, I'd like to get the json properly done in the DB rather than mess with string manipulation outside of it. What am I overlooking here? Any help would be appreciated.</p>