A newer version of this documentation is available.

View Latest

Construction Operators

  • reference

    N1QL supports array and object construction operators.

    Array Constructors

    '[' [ expression [ ',' expression ]* ] ']'
    Syntax diagram

    Arrays are ordered lists with 0 or more values. These values can be one of the defined types. Arrays are enclosed in square brackets ([ ]). Commas separate each value. For example: ["one", "two", "three"] and [1, 2, 3].

    Object Constructors

    '{' [ [string :] expression [ ',' [string :] expression ]* ] '}'
    Syntax diagram

    Objects contain name value members. Objects are enclosed in curly braces {}. Commas separate each pair (member). The colon (:) character separates the key or name from its value within each pair. All keys must be strings and should be distinct from each other within that object. The value can be any supported JSON data type.

    You can use dynamic names in the name-value pairs. The names and values can both be arbitrary expressions. If a name does not evaluate to a string, the result of the object construction is NULL.

    SELECT { UPPER("foo") : 1, "foo" || "bar" : 2 };
        "$1": {
          "FOO": 1,
          "foobar": 2
    Member names are optional when constructing dynamic objects.