Reduce an Array of Objects to a Single Object

INSERT INTO default VALUES ("k01",  {"f1": [{key:"a" value:2, type: "number"}, {key:"b", value: "red", type:"color"}, {key:"c", value: "dog’" type:"pet"} ] });

SELECT OBJECT   v.`key`:v.`value` FOR v IN d.f1 END
FROM default AS d ;

ARRAY evaluates to an array of the operand expression, while FIRST evaluates to a single element based on the operand expression. OBJECT evaluates to an object whose name : value attributes are name-expr : expr .

Name-expr must evaluate to a string. If not, that attribute is omitted from the result object. Duplicates in name-expr overrides attributes

1 Like