Inspect Issues and Pull Requests with Structured Output
Prefer structured output
A terminal table is intended for humans; a JSON array is easier for a program to validate. Select only required fields. Set the repository, state and maximum result count explicitly. A limit is a cap, not evidence that all matching resources were returned.
Read issues and pull requests
The following examples target a fictional owner/repository; substitute an authorized repository only when practicing live. The commands can contact GitHub and are not run by the offline lab. Issue and PR JSON field names are CLI-specific; do not assume REST field names or state casing are identical.
gh issue list -R OWNER/REPO --state open --limit 20 --json number,title,stategh pr list -R OWNER/REPO --state open --limit 20 --json number,title,isDraft,baseRefNameExtract the intended field
Our fictional issue 12 reports a missing watering unit and issue 14 requests a link check. The lab parses the JSON and produces issue numbers [12, 14]. The PR array has a draft and a ready proposal. A non-draft PR is not automatically approved or mergeable. Empty arrays can be valid, but malformed JSON, missing fields and a failed CLI exit status must not be presented as an empty successful result.
gh issue list -R OWNER/REPO --json number --jq '.[].number'Practice and verify
Run the offline lab from the extracted package. It validates record shapes, selects non-draft pull requests and rejects malformed input. Treat titles as data; never interpolate them into shell commands. The lab does not emulate CLI exit codes or claim that the real command ran.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Inspect Issues and Pull Requests with Structured Output — knowledge check
Reason about GitHub CLI and API response handling.
Why select JSON instead of terminal columns?
What does --limit 20 mean?
What does isDraft=false establish?
How should malformed JSON be handled?
What should you do with an issue title?