【发布时间】:2022-01-30 10:22:29
【问题描述】:
在json文件中:
{
"issues": [
{
"key": "key_1",
"component": "my_component",
"textRange": {
"startLine": 1,
"endLine": 11,
"startOffset": 111,
"endOffset": 1111
}
},
{
"key": "key2",
"component": "my component 2",
"textRange": {
"startLine": 2,
"endLine": 22,
"startOffset": 222,
"endOffset": 2222
}
},
{
"key": "my_key3",
"component": "my component 3",
"textRange": {
"startLine": 548,
"endLine": 548,
"startOffset": 14,
"endOffset": 15
}
}
]
}
我想转换为 csv 并添加标题。
我试试这个:
jq -r '.issues[] | ["key","component", "textRange"], [.key,.component, .textRange[]] | @csv' test.issues.json
结果:
"key","component","textRange"
"key_1","my_component",1,11,111,1111
"key","component","textRange"
"key2","my component 2",2,22,222,2222
"key","component","textRange"
"my_key3","my component 3",548,548,14,15
为什么标题是重复的?
【问题讨论】:
-
这能回答你的问题吗? How to add a header to CSV export in jq?