Module 2 · APIs, Reports and the Detector Project · Lesson 6 of 9
Write a report you can read back
Turn the failure counts into deterministic JSON with the input name and processing summary, then load it again to prove it works.
In this lesson · about 18 minutes
- Write structured JSON output with json.dump
- Produce deterministic ordering
- Include processing totals and never overwrite raw input
A good report says what was analysed, what was found, and what was skipped:
{
"input": "cyber-login.csv",
"rejected_rows": 1,
"failed_logins": [
{"user": "root", "source_ip": "203.0.113.45", "count": 10},
...
]
}
- Deterministic ordering: sort by count (highest first), then user, then IP. The same input always gives the same file, so you can compare runs.
- Never write over the raw input. Write a new file.
- Prove it: load the file you wrote and check it.
Exercise
Practice challenge 05: the failed-login report
failures (a Counter keyed by (user, source_ip)) and rejected are ready. Build the report dict shown above, write it to report.json with json.dump, then read it back into a variable called loaded. Sort failed_logins by count (highest first), then user, then IP.
Code that runs before yours
from collections import Counter
failures = Counter({("root", "203.0.113.45"): 10, ("carol", "192.0.2.15"): 5, ("dave", "192.0.2.33"): 4,
("bob", "198.51.100.20"): 1, ("frank", "192.0.2.50"): 1, ("erin", "192.0.2.41"): 1})
rejected = 1Check your understanding0 of 2 correct
Quiz score: 0 of 2
Exercises solved: 0 of 1
Noviq Academy is free and for learning. All data in this course is synthetic and uses documentation IP ranges. Never paste real authentication logs or credentials into online tools. Python runs in your own browser with Pyodide; nothing you type is sent to Noviq.