A small, offline check can catch incomplete configuration before another tool reads it. This script accepts either a local file path or JSON on standard input, verifies that the JSON root is an object, and prints only the missing key names—not values that might contain credentials. It uses Python’s standard `argparse` command-line parsing and `json.loads` decoding. The documented APIs establish those building blocks; the exact configuration-check task is an example built from them, not a documented external service feature.
Before you start
- Intended runner: Python 3.12. This states the intended runner, not a tested minimum version.
- Only Python standard-library modules are used: argparse, json, pathlib, and sys.
- The input file must be readable UTF-8 JSON, or JSON may be supplied on stdin using source `-`.
- Required key names are supplied as one or more values after `--required`. Only top-level object keys are checked.
Build and check
- Save the code as `check_config.py`.
- Create a small synthetic JSON object in a local file, including a harmless dummy value for any credential-like key.
- Run the command with `--required` followed by keys that are present and one that is absent.
- Check that the output lists only the absent key names, in sorted order, and contains no values from the JSON.
- Repeat with stdin using `-`, then try empty, malformed, non-object, and nonexistent-file inputs.
Limits to understand
- This checks key presence only; it does not validate value types, formats, nested keys, or whether a value is safe or usable.
- The script reads the full input into memory; the Python JSON documentation cautions that untrusted JSON can consume substantial CPU and memory, so use appropriately bounded local fixtures.
- Missing keys return exit status 1; input and validation errors return 2; a complete configuration returns 0. No retries are performed.
What this example adds
There is no upstream code to adapt. The proposed example turns the documented command-line parser and JSON decoder into a local configuration check, adds file-or-stdin input, sorted missing-key output, and error handling that avoids displaying configuration contents.
Run it
Save as `check_config.py`. Run `python3.12 check_config.py settings.json --required api_url token`; use `-` instead of the path to read JSON from standard input, for example `printf '{"api_url":"local","token":"hidden"}' | python3.12 check_config.py - --required api_url token`.Example input
Local file `settings.json`:
{"api_url":"https://example.invalid","token":"do-not-print","region":"test"}
Command:
`python3.12 check_config.py settings.json --required token api_url region signing_key`Expected output
missing keys: signing_key
The configured values, including `token`, are not printed.
