JSON and CSV Output
Outcome: GoAccess reports as data — the panel structure in JSON, the same numbers as CSV rows — read back and checked by a second program.
JSON: the panels as a document
Change the output name's ending and the same run writes JSON instead:
goaccess access.log --log-format=COMBINED \
-o report.json --json-pretty-print
(--json-pretty-print trades compactness
for readability; leave it off for
machines.) The document opens with a
general block — the dashboard's
headline numbers as fields — followed by
one block per panel. From the lab's real
output (transcript t04-json-output.txt,
full file at goaccess-lab/report.json):
general.total_requests = 27
general.valid_requests = 27
general.failed_requests = 0
general.unique_visitors = 5
general.bandwidth = 5056
panels: visitors, requests, static_requests,
not_found, hosts, os, browsers,
visit_time, referring_sites, status_codes
Each panel carries a data list of rows,
and each row carries its counts under
named keys — hits.count,
visitors.count, and the row's label as
data. The requests panel, read back by
the lab's Python check:
9 hits, 5 visitors /
4 hits, 3 visitors /about.html
4 hits, 2 visitors /guide.html
1 hit, 1 visitor /guide.html?ref=newsletter
1 hit, 0 visitors /guide.html (the POST)
Two honest details live in that list.
The query-string request counts as its
own row — GoAccess treats
/guide.html?ref=newsletter as a
different URL from /guide.html, which
is true to the log and worth knowing
before you compare page counts with
another tool. And the refused POST shows
0 visitors: visitor counting follows the
successful-visit logic, not raw hits.
Reading it back
Because it is ordinary JSON, anything
that reads JSON can audit it. The lab's
checker was a few lines of Python
(kept inside transcript t04):
python3 -c "import json; d=json.load(open('report.json')); print(d['general']['total_requests'])"
That prints 27. The point is larger
than the trick: a report you can
recompute from is a report you can
trust in a pipeline — a nightly job that
archives JSON, a script that alarms when
the not-found count jumps, a spreadsheet
fed by chapter 7's other output.
CSV: the flat shape
goaccess access.log --log-format=COMBINED -o report.csv
CSV output flattens every panel into rows of quoted fields — a leading index, the panel name in the third field, the value, and the metric's name at the end:
"1",,"general",,,,,,,,"27","total_requests"
"5",,"general",,,,,,,,"5","unique_visitors"
"9",,"general",,,,,,,,"2","unique_not_found"
It is not pretty, and it is not meant to
be read raw: it is meant to be imported
— into a spreadsheet, a database, a
plotting tool. (--no-csv-summary drops
the summary rows if your importer
prefers pure panel data.) Between the
three machine shapes the rule of thumb
is: JSON for programs you write, CSV for
tools you already have, HTML for people.