title: Combine other columns as JSON without aggregating
body: <p>I have a query with a number of columns in Postgres. All of the columns except for the other two are to be combined as a JSON in single result. I tried something like this:</p>
  
  <pre><code>SELECT  date_time, id, 
          json_build_object(
              'col1', json_agg(col1),
              'col2', json_agg(col2),
              ...
              'coln', json_agg(coln)
          ) AS attributes
  FROM mytable;
  </code></pre>
  
  <p>The problem is that the query complains that it requires aggregation on the other two columns not belonging to JSON. I don't want to aggregate, I simply want to JSONize the other columns per row.</p>
  
  <p>I also tried this:</p>
  
  <pre><code>SELECT  date_time, id, 
          to_json(col1, col2, ..., coln)
  FROM mytable;
  </code></pre>
  
  <p>but didn't work. How should I structure my query and/or what Postgres JSON function should I use?</p>
  
  <p>I am using Postgres v9.6.1.1.</p>