假设json
{
  "a": "aa",
  "b": {
    "ba": "x"
  }
}
而我们访问:
$ jq -r '.c' $JSON 
null
输出一个null串,有些时候并不想要这个串,让它变成空串("")好了。
首先可以用if-then-else这样写:
$ jq -r 'if .a == null then "" else .a end' $JSON
或者
$ jq -r '.a | if . == null then "" else . end' $JSON
还可以用替换操作运算符(Alternative operator):
$ jq -r '.c // ""' $JSON
https://stedolan.github.io/jq/manual/#Alternativeoperator://