Use this small offline CLI to summarize numeric observations already saved in a JSON file, or supplied through standard input. It does not contact or test an external service, and the result describes only the provided data.
Before you start
- Python 3.12 is the intended runner; the cited Python 3.12 documentation describes the standard-library `json` module and finite-value concerns for statistical data.
- Provide a UTF-8 JSON file path or pipe one JSON document to stdin. The top-level value must be an array.
- Every array item must be a finite integer or float. Booleans, strings, null, arrays, objects, NaN, and infinities are rejected.
- The summary is only about the saved values supplied to the program; it is not a live-service check or financial advice.
Build and check
- Save the code as `summarize_numbers.py`.
- Create a synthetic fixture containing `[2, 4, 6]` and run `python3.12 summarize_numbers.py observations.json`.
- Confirm the displayed count, minimum, maximum, and mean match the fixture.
- Try an empty array, malformed JSON, a non-array top-level value, a boolean or string element, and a non-finite number; confirm empty input is explicit and invalid input exits with an error.
- Run with a nonexistent file path and confirm the missing-file error is written to stderr.
Limits to understand
- This reports descriptive statistics for only the values supplied; it does not establish whether observations are representative or current.
- The mean may be sensitive to outliers. No filtering, coercion, or missing-value imputation is performed.
- Parsing untrusted JSON can consume significant CPU or memory; use appropriately small local input files.
- A finite input set can still produce an unrepresentable floating-point mean for extreme values; that case is reported as an error.
What this example adds
The script accepts either a file path or stdin, gives empty arrays an explicit result instead of attempting min/max or mean, and reports malformed JSON, wrong top-level types, invalid elements, and missing files as readable errors on stderr with a nonzero exit status. It validates JSON constants such as NaN and Infinity, as well as numeric values, and checks that the computed mean remains finite. Results go to stdout only. The processing is local and read-only; it summarizes saved observations, not a live service or current data.
Run it
Save as `summarize_numbers.py`, then run `python3.12 summarize_numbers.py observations.json` or pipe input with `printf '[2, 4, 6]\n' | python3.12 summarize_numbers.py`. The intended runner is Python 3.12; no other minimum-version claim is made. There are no network calls, retries, or timeout requirement.Example input
[2, 4, 6]Expected output
count: 3
min: 2
max: 6
mean: 4.0
