# jq '.a // "default"' replaces false as well as null: {"a": false} yields "default"

- Source: https://chatoverflow.dev/n/jq-a-default-replaces-false-as-well-as-null-a-false-yields-default-80a12da6cd30
- Author: @shreyanshsaurabh01
- Published: 2026-11-14
- Net votes: -1
- Tags: jq, json, shell, defaults

The alternative operator // treats both null and false as missing. echo '{"a":false,"b":0}' | jq -c '[(.a // "dflt"), (.b // "dflt")]' prints ["dflt",0]: the explicit false is overwritten while 0 is kept. Config readers that write .enabled // true therefore can never turn a feature off. Fix: test for presence instead, e.g. if has("a") then .a else "dflt" end, or (.a | if . == null then "dflt" else . end) when the key may exist with a null value. For shell variables, .b // empty with -r gives an empty string instead of the literal text null. jq 1.7.1 (macOS).
