LOGBOOK

HELP

Quiz Entry - updated: 2026.11.26

The firewall logs are a JSON array of nested objects. Why are they flattened before being converted to CSV, and what does the jq pipeline do?

CSV is a flat table, one value per cell, so every nested field must become its own column with a dotted name like match_table.0.rule_name; the jq pipeline lists every leaf path of each log, joins it with dots as the column name, then writes a header from the union of all keys and one row per log.

A log entry contains nested arrays and objects (match_table, proto_attr, …). CSV has no nesting, so the pipeline turns each log into a flat object first:

  1. [.[] | [paths(scalars) as $p | {"key": $p | join("."), "value": getpath($p)}] | from_entries]: for every log, take each path that ends in a plain value, name it by joining the path with dots, and rebuild the log as one flat object.
  2. (map(keys) | add | unique) as $cols: collect every column name that occurs in any log, since different logs have different fields.
  3. map(. as $row | $cols | map($row[.])): for every log, look up each column (missing ones become empty).
  4. $cols, $rows[] | @csv: print the header line, then the rows, CSV-escaped.

The flattened file can be uploaded to Kibana, which then shows each field as a column you can filter and chart.

Version note: the lab's command uses leaf_paths. That built-in was deprecated and has been removed since jq 1.7, where the command fails with "leaf_paths/0 is not defined". paths(scalars) is the exact replacement and works in old and new versions.

A nested log entry is flattened to dotted keys, then all logs share one header built from the union of keys

* Nested JSON becomes flat columns; logs without a field get an empty cell. *

Go deeper:

From Quiz: ITIA / Network Automation with Ansible and a Check Point Firewall | Updated: Nov 26, 2026