Skip to main content
Version: v1.11.0

flatten

Function

flatten transform a record into a flattened array.

Synopsis

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

Description

The flatten function returns an array of records [{key:[string],value:<any>}] where key is a string array of the path of each record field of val and value is the corresponding value of that field. If there are multiple types for the leaf values in val, then the array value inner type is a union of the record types present.

Examples

echo '{a:1,b:{c:"foo"}}' | zq -z 'yield flatten(this)' -

=>

[{key:["a"],value:1},{key:["b","c"],value:"foo"}]