title: Postgres treat selected json_agg'regated string as an array
body: <p>In the following query(*), I am finding that <code>foo_ids</code> comes back as a string representation of the array. When I finally run <code>to_json</code> on my <code>ActiveRecord::Base.connection.select_all</code> result, I see that it of course gets represented as a string in the resulting output.</p>
  <pre><code>SELECT
    bar.a,
    bar.b,
    bar.c,
    (
      SELECT JSON_AGG(DISTINCT foo_id)
      FROM foo
      WHERE bar.id = foo.bar_id
    ) AS foo_ids
  FROM bar
  </code></pre>
  <p>Is there anything I can do to get the desired selection as an array into the final JSON output without having to modify the intermediate result?</p>
  <p>(*) The query has been simplified for this question.</p>