Symptom
Cribl Stream receives an HEC event whose body field contains a JSON array encoded as a string. The array is not available for direct unrolling. For example, the parsed envelope contains body similar to this value:
"["timestamp":"2042-42-42T18:00:00.000","transaction_id":"..."]"
The escaped quotes indicate that body is a string, not a native array.
Environment
- Cribl Stream pipeline processing HTTP Event Collector (HEC) events
- HEC payloads with a JSON-encoded array inside the
bodyfield
Resolution
- Navigate to Processing and select Pipelines.
- Create or import a pipeline.
- Add a Parser function in Extract mode with type JSON and source field
_raw. - Add an Eval function that assigns
events = JSON.parse(body). - Add an Unroll function with source expression
eventsand destination fieldmy_event. - Add an Eval function that assigns
_raw = JSON.stringify(my_event). - Remove the scratch fields
events,my_event,body,headers, and__json. - Save the pipeline and verify that each array element produces a separate event.
Cause
This can be caused by:
- The HEC envelope stores the inner array as escaped JSON text in
body. - Unroll receives a string until
JSON.parse(body)converts it into an array.
Additional Information
- To promote event fields to the top level, add a Parser in Reserialize mode or expand
my_event.*with a final Parser. - To retain the HEC application header, assign
my_event.app = headers['x-app-name']before cleanup. - To flatten nested
extracted_dataarrays, add another Unroll function or reduce the array into an object with Eval. - For the Unroll function’s source-expression and destination-field behavior, see Cribl Stream Unroll documentation.
- For JSON-array handling based on parsed
_rawcontent, see Cribl Stream JSON Unroll documentation.
