By the end of this lesson
Save a recipe, supply a tiny input file and compare its complete result with a known example.
Before you start
- Lesson 8; Python 3.12 available.
- The local file-transfer workflow from lesson 6.
Three words to know
- JSON
- A text format for data, with objects, arrays, strings and other value types.
- stdin
- The input stream a program can read; a shell can connect a file to it.
- Argument
- A value supplied after a command, such as the field name status.
1. Inspect the published recipe first
This practice uses “Count JSON records by an explicit string field with Python”, version 0.1.0. The lesson’s downloadable count_records.py is the published source version whose SHA-256 matched the site’s verified code hash when this lesson was prepared. Read the recipe’s requirements, limits, MIT licence and recorded test scope. Those tests do not establish correctness for every possible input.
Save it in the local practice folder from lesson 6, with the exact name count_records.py. Inspect the file as plain text before executing it. It should begin with a Python shebang and imports, not an HTML page. If your browser added .txt, rename the file to the documented .py name.
Edit the username and documentation-only address before running.
scp ./count_records.py learner@203.0.113.10:openvist-learn/count_records.py2. Create tiny synthetic data
cd "$HOME/openvist-learn"
cat > records.json <<'JSON'
[{"status":"open"},{"status":"closed"},{"status":"open"}]
JSONWhat you should see · example output
No output is normally printed.
The outer brackets form an array. Each object has one status string. You can inspect this JSON using OpenViST’s JSON Validator; that browser tool validates data but does not execute the Python recipe.
3. Run and compare
python3 count_records.py status < records.jsonWhat you should see · example output
{"records": 3, "groups": [{"value": "closed", "count": 1}, {"value": "open", "count": 2}]}status is a literal top-level field name. The < operator feeds records.json into stdin; it is not a Python comparison. The result contains three records and two groups, sorted by their values. JSON whitespace may differ from the compact example on the recipe page without changing these values.
4. Inspect the exit status
python3 count_records.py status < records.json
printf 'exit=%s\n' "$?"What you should see · example output
The JSON result, followed by exit=0.
The shell’s $? refers to the most recent command. Read it immediately after the command you are checking. This recipe returns 2 on rejected input; a successful process exit is not a general security or data-quality certification.
YOUR TURN
A small check before you continue
Change one of the two open statuses to closed, run again and predict both counts.
Show a suggested answer
The result should have closed count 2, open count 1 and records 3. The code should not need modification.
Sources and scope
Documentation and examples reviewed 2026-10-18. Provider screens, package versions and output wording can differ. Examples show expected outcomes; they are not a claim that OpenViST connected to your server or verified your setup.
