English 中文(简体)
jq: Defaulting multiple possibly-nonexistent key, in nested path?
原标题:
  • 时间:2023-07-29 02:46:56
  •  标签:
  • jq

I d like to default values in place on jq, and return root document.

What I have (note that some property is missing from the inner object):

[{"foo":{}},{"foo":{"a":1}},{"foo":{"b":4,"c":23}},{"foo":{"a":15,"b":2,"c":33}}]

What I want (default missing property with 0):

[
  {
    "foo": {
      "a": 0,
      "b": 0,
      "c": 0
    }
  },
  {
    "foo": {
      "a": 1,
      "b": 0,
      "c": 0,
    }
  },
  {
    "foo": {
      "a": 0,
      "b": 4,
      "c": 23
    }
  },
  {
    "foo": {
      "a": 15,
      "b": 2,
      "c": 33
    }
  }
]

I ve tried something like jq .[] | (.foo | getpath(["a"]) //= 0) < in > out, but this returns stream of the inner object instead of root document; this is not what I wanted because there are other property to grouping record, I would like to group by it later.

问题回答

暂无回答




相关问题
why can t $module be used as a variable name? in jq

Is this behaviour of jq, w.r.t the non-allowed use of $module as a variable name, specified anywhere? $ jq -n --arg module X $module jq: error: syntax error, unexpected module, expecting IDENT ...

热门标签