Select multiple properties in an ARRAY clause in N1QL

Currently, I can do the following

ARRAY friend.name FOR friend IN friends END

which gives me an array of names for the array of friends. Suppose I want the array to contain objects like so

{
   name: "John Doe",
   status: "His status"
}

it is tempting to do something like

ARRAY friend.name, friend.status FOR friend IN friends END

However, this doesn’t work.
Any help would be greatly appreciated.

Here is what you can do – wrap the properties in an object:

1 Like

Fantastic! Thank you.

I was looking for this wrapping json in queries functionality in the n1ql language reference but couldn’t find it anywhere. Is it written in there?

Thanks.

Sent a note to our docs team. In general, you can construct objects anywhere within your query.

1 Like