Convert result of a N1QL to array

query
n1ql

#1

I have a query of the form

SELECT MAX([fr.id,fr.observedAtTime,fr])[2] AS r FROM default AS m1 UNNEST `entityVersions` AS fr 
WHERE m1.accountId = 2 AND fr.`name` = "foo" GROUP BY fr.id

which return results of the form

[
  {
    "r": {
      "id": "61280149-d1f5-44bc-a2de-f1ccbb259532",
      "inactive": false,
      "labels": {},
      "observedAtTime": 23,
      "properties": {},
    }
  },
  {
    "r": {
      "id": "ccb3f93c-e12f-4825-ae8b-5f19a3116fb1",
      "inactive": false,
      "labels": {},
      "observedAtTime": 23,
      "properties": {
      }
    }
  }
]

I want the results to be a single array of json objects like this

[
  {
    "r":[{
          "id": "61280149-d1f5-44bc-a2de-f1ccbb259532",
          "inactive": false,
          "labels": {},
          "observedAtTime": 23,
          "properties": {},
      },
      {
          "id": "ccb3f93c-e12f-4825-ae8b-5f19a3116fb1",
          "inactive": false,
          "labels": {},
          "observedAtTime": 23,
          "properties": {}
      }]
  }
]

#2
SELECT ARRAY_AGG(d.r) AS r FROM (SELECT MAX([fr.id,fr.observedAtTime,fr])[2] AS r FROM default AS m1 UNNEST `entityVersions` AS fr 
WHERE m1.accountId = 2 AND fr.`name` = "foo" GROUP BY fr.id) AS d