title: Postgres query result to json object
body: <p>My query is given below </p>
  
  <pre><code>SELECT w.payload,
         Count('payload') OVER () AS ROWCOUNT
  FROM wholesale_confirmation.wholesale_order_confirmation w
  WHERE w.delivery_date = COALESCE(NULL, w.delivery_date)
    AND w.ship_to_location_id = COALESCE(NULL, w.ship_to_location_id)
    AND w.order_raised_date = COALESCE(NULL, w.order_raised_date)
    AND w.ship_from_location_id = COALESCE(NULL, w.ship_from_location_id)
  LIMIT 10
  OFFSET 0;
  </code></pre>
  
  <p>which is giving me result like this:</p>
  
  <p><a href="https://i.stack.imgur.com/a0snv.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/a0snv.png" alt="Result"></a></p>
  
  <p>I want instead <code>{"payload:"[payload1,payload2,payload3],"rowcount":n}</code>.</p>
  
  <hr>
  
  <p>Postgres version <strong>10.3</strong>, <code>payload</code> data type is <code>jsonb</code></p>