Flatten in Cribl Stream
Nested key handling and collapse settings, per the Flatten function page.
What the function does
The Flatten Function page in the Cribl Stream documentation describes a Function that works on nested data. The page says it pulls fields out of a nested structure, moving nested key-value pairs (fields) up to a higher level in the object. Around that behavior, the page lists four things you can specify: the individual fields to flatten, the depth at which to flatten fields, the delimiter to use when concatenating keys, and an optional prefix to add to transformed field names.
The page attaches a note to that behavior. It reads, in full, that the Flatten Function creates fully qualified names for promoted fields, and that if you simply need to promote fields without transforming their names, you should use the eval Function instead, which is the Function the note links to. In other words, the two Functions cover different tasks: promotion with newly built fully qualified names versus promotion that leaves names as they were.
In the page's example, the promoted fields land at the top level of the object. Each one carries a fully qualified name built from the parent key, the element's index in its array, and the nested field name, joined with the default underscore delimiter: for the first element of the accounting array the output shows accounting_0_firstName, accounting_0_lastName, and accounting_0_age, and for the second element of the sales array it shows sales_1_firstName, sales_1_lastName, and sales_1_age.
How it is configured
The Usage section of the page documents seven settings. The first three describe how the Function runs, and the remaining four, Fields, Prefix, Depth, and Delimiter, control the flattening itself.
- Filter: Filter expression (JavaScript) that selects data to feed through the Function. Defaults to
true, meaning it evaluates all events. - Description: Simple description of this Function. Defaults to empty.
- Final: Toggle on to stop feeding data to the downstream Functions. Default is toggled off.
- Fields: List of top-level fields to include for flattening. Defaults to an empty array, which means all fields. Limit to specific fields by typing in their names, separated by hard returns. Supports wildcards (
*). Supports double-underscore (__) internal fields only if individually enumerated - not via wildcards. - Prefix: Prefix string for flattened field names. Defaults to empty.
- Depth: Number representing the nested levels to consider for flattening. Minimum
1. Defaults to5. - Delimiter: Delimiter to use for flattening. Defaults to
_(underscore).
The first three settings govern execution rather than the transformation itself. Filter is the JavaScript expression that selects the data to feed through the Function; because it defaults to true, the Function evaluates all events unless the expression selects less. Description is a simple description of this Function, and it defaults to empty. Final, toggled on, stops feeding data to the downstream Functions, and the page says the default is toggled off.
The Fields setting decides which top-level fields are included for flattening, and its default, an empty array, means all fields. To narrow that, you type specific field names into the list, separated by hard returns. The list supports wildcards, with one documented exception: double-underscore internal fields are supported only if individually enumerated, not via wildcards.
Depth is the number representing the nested levels to consider for flattening; the page sets its minimum at 1 and its default at 5. Delimiter is the delimiter to use for flattening, and it defaults to the underscore. Prefix, documented as the prefix string for flattened field names, defaults to empty. The opening list phrases the same setting as an optional prefix to add to transformed field names, which is how the page introduces it before the Usage section.
Example from the page
The page's Example section starts by adding a test sample in Preview > Paste a Sample. The sample event, copied from the Flatten Function page, holds two top-level fields, accounting and sales, and each one holds an array of two objects with firstName, lastName, and age fields:
{
"accounting": [{
"firstName": "John",
"lastName": "Doe",
"age": 23
}, {
"firstName": "Mary",
"lastName": "Smith",
"age": 32
}],
"sales": [{
"firstName": "Sally",
"lastName": "Green",
"age": 27
}, {
"firstName": "Jim",
"lastName": "Galley",
"age": 41
}]
}
The four people the sample carries are John Doe, age 23, and Mary Smith, age 32, under accounting, and Sally Green, age 27, and Jim Galley, age 41, under sales. The page's steps continue with the sample itself: under Select Event Breaker, choose ndjson (newline-delimited JSON), and select Save as a Sample File.
The page then shows sample output with all settings at default, copied from the Flatten Function page:
{
"accounting_0_firstName": "John",
"accounting_0_lastName": "Doe",
"accounting_0_age": 23,
"accounting_1_firstName": "Mary",
"accounting_1_lastName": "Smith",
"accounting_1_age": 32,
"sales_0_firstName": "Sally",
"sales_0_lastName": "Green",
"sales_0_age": 27,
"sales_1_firstName": "Jim",
"sales_1_lastName": "Galley",
"sales_1_age": 41,
}
Read together, the two blocks show the nested arrays unwinding into top-level fields. Every object in the two arrays contributes fields named from the parent key, the element's index, and the field name, joined with the default underscore, so the accounting array unwinds into the names beginning accounting_0_ and accounting_1_ and the sales array into the names beginning sales_0_ and sales_1_. The values carry over unchanged from the input, for example accounting_0_firstName holding "John" and accounting_0_age holding 23.
The page's wrap-up is brief: using the Flatten Function's default settings, the Function successfully creates top-level fields from the nested JSON structure, as expected.
What the docs flag
The note from the opening section is the page's main routing guidance. Because the Flatten Function creates fully qualified names for promoted fields, the note directs work that only needs promotion, without transforming names, to the eval Function.
Two settings carry explicit boundaries. Fields: double-underscore internal fields are supported only if individually enumerated, not via wildcards. Depth: its minimum is 1, so at least one nested level is always in scope. The example's output carries a scope of its own: the page labels it sample output with all settings at default, so it shows what the defaults produce rather than a tuned configuration.
For context beyond the Function itself, the page's See Also section links to the Reducing Windows XML Events use case, which the page describes as demonstrating flattening within _raw events ingested via Windows XML. It is the page's pointer for seeing the Function applied to a real source format rather than a pasted sample.
Frequently asked questions
What does the Flatten Function in Cribl Stream do?
It pulls fields out of a nested structure, moving nested key-value pairs up to a higher level in the object. The page adds that the Function creates fully qualified names for the promoted fields.
What are the default settings for the Cribl Stream Flatten Function?
Filter defaults to true so it evaluates all events, Fields defaults to an empty array meaning all fields, Description and Prefix default to empty, Depth defaults to 5 with a minimum of 1, and Delimiter defaults to the underscore. Final is toggled off by default.
What does the Flatten Function example produce with all settings at default?
The nested objects in the accounting and sales arrays become top-level fields such as accounting_0_firstName and sales_1_age, with the parent key, element index, and field name joined by the default underscore. The page says the Function successfully creates top-level fields from the nested JSON structure, as expected.
When does the Flatten Function page point to the eval Function instead?
When you simply need to promote fields without transforming their names, the page's note says to use the eval Function. The note gives the reason: the Flatten Function creates fully qualified names for promoted fields.
Source
Verified against Cribl Stream 4.20 documentation on November 17, 2026.