title: Count all rows and show a limited number of them in a single json object
body: <p>My query is </p>
  
  <pre><code>select array_to_json(array_agg(row_to_json(t))) from (
      select count(*) over() as total, id,title
      FROM notifications 
      WHERE  title ilike '%a%'
  LIMIT 5 OFFSET 1)t
  </code></pre>
  
  <p>and the output is</p>
  
  <pre><code>[
      {
          "title": "Sartaj                                                              ", 
          "id": 3,
          "total":16
      }
  ]
  </code></pre>
  
  <p>The result includes the total in object, but I want to move it outside the object.</p>
  
  <p>My expected answer is</p>
  
  <pre><code>[
      "total":16,
      "data":[
  {
          "title": "Sartaj                                                       ", 
          "id": 3
      }]
   ]
  </code></pre>
  
  <p>I also tried </p>
  
  <pre><code>with tmp_notifications as (
      SELECT id,title,description,img_url,link,created_on from notifications 
      where title ilike '%universi%'
      ) 
      select row_to_json(t) from (
          select count(*) as data_count,
          (json_agg(json_build_object('description',description,'title',title,'created_on',created_on,
          'link',link,'img_url',img_url,'id',id)) 
           ) as data from tmp_notifications limit 1
          )t
  </code></pre>
  
  <p>but limit is not working here.</p>