Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
使用jq将 json 数组转换为 csv 会导致:
jq
$ echo '["a",1,true,"comment"]' | jq '.|@csv' "\"a\",1,true,\"comment\""
我很惊讶整个数组变成了一个字符串而不是一个值列表。我该怎么做才能得到
"a",1,true,"comment"
反而?
您误解了@过滤器的意义。这些是字符串格式化过滤器,它们产生字符串。因此@csv将数组的字符串表示形式返回为 csv 行。这正是它应该做的。返回“未字符串化”版本是错误的,因为无法进一步处理。
@
@csv
如果您想要原始的“未字符串化”输出,请使用-r原始输出选项。
-r
$ echo '["a",1,true,"comment"]' | jq -r '@csv' "a",1,true,"comment"