Skip to main content
Version: v1.18.0

unflatten

Function

unflatten transform an array of key/value records into a record.

Synopsis

unflatten(val: [{key:string|[string],value:any}]) -> record

Description

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.

Examples

Simple:

echo '[{key:"a",value:1},{key:["b"],value:2}]' |
zq -z 'yield unflatten(this)' -

=>

{a:1,b:2}

Flatten to unflatten:

echo '{a:1,rm:2}' |
zq -z 'over flatten(this) => (
key[0] != "rm"
| yield collect(this)
)
| yield unflatten(this)
' -

=>

{a:1}