01 / Reproduce
Reproduce the switch
Install jq from the release linked below and confirm jq --version runs. Extract the practice ZIP, open PowerShell in that folder, and run the first filter. The ZIP uses filter files so the shell can pass the jq expressions through without inline quoting.
jq -f fallback.jq cases.json
The filter in fallback.jq applies one expression to each object.
map({id, include_draft: (.include_draft // true)})
For a single field value, jq’s // uses the right side when the left side yields false or null. An omitted field reads as null here. The unguarded filter prints true for the explicit off, omitted, and explicit null cases. It also passes the string "false" through as a string.
02 / Inspect
Check whether the key exists
Use has("include_draft") to detect omission. When the key is present, use type to accept JSON Booleans. Mark other present values invalid so the caller has a state it can handle explicitly.
map(
if has("include_draft") | not then
{id, state: "defaulted", include_draft: true}
elif (.include_draft | type) == "boolean" then
{id, state: "explicit", include_draft}
else
{id, state: "invalid", include_draft: null}
end
)
Run the guarded filter and then check both full outputs. The final command prints true and exits successfully when both match the expected records. The ASCII encoding here is for these ASCII-only fixtures.
jq -f fallback.jq cases.json | Set-Content -Encoding ascii fallback-result.json
jq -f preserve.jq cases.json | Set-Content -Encoding ascii preserved-result.json
jq -ne --slurpfile fallback fallback-result.json --slurpfile preserved preserved-result.json -f check.jq
The guarded result preserves explicit false and true. It supplies the default for the omitted key and marks both null and "false" invalid. An invalid row carries include_draft: null to indicate that it has no Boolean decision.
03 / Make it your own
Write down what omission means
- Copy
cases.jsontomy-cases.json. Add{"id": "number-zero", "include_draft": 0}to the array. - Run both filters. The fallback should keep the number
0. The guarded filter should mark it invalid. - Pick an optional Boolean from a preview or report workflow you maintain. Write down the expected behavior for omission, explicit
false, explicittrue, and invalid values. Update the practice filter and its expected records together.
jq -f fallback.jq my-cases.json
jq -f preserve.jq my-cases.json
Boundaries
Apply the policy at the handoff
The lab expects an array of objects with IDs and checks one field. In a real preview pipeline, validate the surrounding structure and decide how the caller handles an invalid state before using the result. Choose the default based on what the preview can expose. The sample exercises a local jq transformation. Model behavior, report rendering, downstream actions, and performance remain untested.
Primary sources / Checked November 11, 2026
Read the jq references
- Fallback behavior for false and null. jq 1.8 manual on the alternative operator
- Key presence and the value’s JSON type. jq 1.8 manual on
hasand thetypefunction - Platform downloads for the version used in the lab. Official jq 1.8.2 release
Downloads / Practice and social files

