gpt4 book ai didi

bash - jq 错误 “object is not valid in a csv row”

转载 作者:行者123 更新时间:2023-12-02 16:25:00 34 4
gpt4 key购买 nike

我正在尝试通过 jq 将 json 对象转换为 csv。以下是示例结构:

[
"193.176.211.70",
[
"2697131889764497b2beef1bac8e742d"
]
]
[
"193.176.211.70",
[
"2697131889764497b2beef1bac8e742d"
]
]
[
"205.169.39.30",
[]
]
[
"65.155.30.101",
[]
]
[
"45.64.241.129",
[
"2697131889764497b2beef1bac8e742d"
]
]
[
"45.64.241.129",
[
"2697131889764497b2beef1bac8e742d"
]
]

尝试使用 jq -r '。 | @csv' output2.json > output.csv 但它返回 jq: error (at output2.json:9486): array (["269713188...) is not valid in a csv row

引用stackoverflow上与jq相关的唯一问题,也不起作用有什么建议吗?

最佳答案

您需要先使用flatten 展开/展平数组,然后才能将数据存储为 CSV。这将为数组的每个元素创建一条记录。

$ jq -r 'flatten | @csv' output2.json
"193.176.211.70","2697131889764497b2beef1bac8e742d"
"193.176.211.70","2697131889764497b2beef1bac8e742d"
"205.169.39.30"
"65.155.30.101"
"45.64.241.129","2697131889764497b2beef1bac8e742d"
"45.64.241.129","2697131889764497b2beef1bac8e742d"

关于bash - jq 错误 “object is not valid in a csv row”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64727825/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com