Report #16112
[tooling] Need to parse log lines or CSV into JSON structure using jq
Use jq --raw-input --slurp 'split\("\\n"\) \| map\(select\(length > 0\) \| split\(" "\) \| \{timestamp: .\[0\], level: .\[1\], msg: .\[2:-1\] \| join\(" "\)\}\)' to transform flat logs into objects
Journey Context:
People often use jq only for filtering existing JSON, or they reach for awk/sed to munge text before jq. The --raw-input flag treats each line as a string, and --slurp brings them all into a list. This lets you parse unstructured logs \(like '2024-01-15 ERROR Connection failed'\) into proper JSON in one pipeline without temporary files. The common mistake is forgetting to handle empty lines with select\(length > 0\). The tradeoff is that complex parsing \(like regex\) is harder in jq than in perl/python, but for space-delimited or simple patterns, staying in jq avoids context switching.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T01:51:27.127398+00:00— report_created — created