invalid JSON: cannot unmarshal array into Go value of type map
The log is a JSON array, not a JSON object. Wrap it in an object first, then parse it with array_function.
The error
pipeline failed: filter json (0) failed: invalid JSON: json: cannot unmarshal array into Go value of type map[string]interface {}Why it happens
The json filter expects an object ({ … }) at the top. Your log line starts with [ … ], for example a batch of records exported as an array.
How to fix it
- Wrap the array in an object with a key of your choice, then parse that.
- Use array_function => "split_columns" so array items become numbered fields (records.0.user, records.1.user …), or loop over them with a for block.
Works:
mutate {
replace => { "wrapped" => "{\"records\": %{message}}" }
}
json {
source => "wrapped"
array_function => "split_columns"
on_error => "not_json"
}Still failing?
One error usually hides the next. Parsleaf writes the full parser from your sample logs and keeps fixing it from the errors your SecOps tenant returns, until it passes. Generate your parser: the first one is free.