Reduce an Array of Objects to a Single Object

I need to reduce an array of objects into a single object, like so:

[{key:‘a’, value:2, type: ‘number’}, {key:‘b’, value: ‘red’, type:‘color’}, {key:‘c’, value: ‘dog’, type:‘pet’} ] => {a:2, b: ‘red’, c: ‘dog’}

please help

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