unflatten — transform an array of key/value records into a record.
unflatten(val: [{key:string|[string],value:any}]) -> record
The unflatten function converts the key/value records in array val
into
a single record. unflatten is the inverse of flatten, i.e., unflatten(flatten(r))
will produce a record identical to r
.
Simple:
echo '[{key:"a",value:1},{key:["b"],value:2}]' |
super -z -c 'yield unflatten(this)' -
=>
{a:1,b:2}
Flatten to unflatten:
echo '{a:1,rm:2}' |
super -z -c 'over flatten(this) => (
key[0] != "rm"
|> yield collect(this)
)
|> yield unflatten(this)
' -
=>
{a:1}