如何在jq中对字段值进行多重赋值?

How to make multiple assignment of field values in jq?

我有这样的 jq 命令:

jq --arg ts "$TS" '.Date = $ts, .Marker.Date = $ts, .InfoFromTerminator.Timestamp = $ts'

但它似乎只替换了最后一项,保持前两项不变。如何重写查询以替换所有 3 个参数?

逗号是 jq 中的运算符:

Even the comma operator is a generator, generating first the values generated by the expression to the left of the comma, then for each of those, the values generate by the expression on the right of the comma.

更改多个元素可以通过管道从一个 filter/assignment 到下一个来完成,如下所示:

jq --arg ts "$TS" '.Date = $ts | .Marker.Date = $ts | .InfoFromTerminator.Timestamp = $ts'