flatten
Flattens nested data.
Synopsis
flatten [<separator>]
Description
The flatten
operator acts on container types:
- Records: Join nested records with a separator (
.
by default). For example, if a field namedx
is a record with fieldsa
andb
, flattening will lift the nested record into the parent scope by creating two new fieldsx.a
andx.b
. - Lists: Merge nested lists into a single (flat) list. For example,
[[[2]], [[3, 1]], [[4]]]
becomes[2, 3, 1, 4]
.
For records inside lists, flatten
"pushes lists down" into one list per record
field. For example, the record
becomes
Lists nested in records that are nested in lists will also be flattened. For example, the record
becomes
As you can see from the above examples, flattening also removes null
values.
<separator>
The separator string to join the field names of nested records.
Defaults to .
.
Examples
Consider the following record:
After flatten
the record looks as follows:
Note that dns.grouped.A
no longer contains a null
value.