【发布时间】:2019-11-27 01:06:51
【问题描述】:
我正在尝试将此 json https://pastebin.com/1ch1CzM4 转换为 csv,以便将其全部导入数据库,但我一直遇到错误。我得到的最接近的是
./jq -r '[.[]] | @csv'
但是这并没有起到作用,因为它是嵌套的。非常感谢任何帮助。
我试图让父母作为第一行,所以“地址、舒适组、check_in_time、check_out_time”,然后如果其中有一个 json,它只是 csv 中的一个平面 json 文本。
如果我尝试
jq -r '[[.address, .amenity_groups, .check_in_time, .check_out_time] | map(tostring) | @csv] | map(tostring) | @csv'
那么输出就是
"""140 Ancien Chemin De Berre, Lambesc"",""[{""""amenities"""":[""""Garden"""",""""Terrace""""],""""group_name"""":""""General""""}]"",""16:00:00"",""10:00:00"""
vs 想要的
address, amenity_groups, check_in_time, check_out_time
$json_of_address, $json_of_amenity_groups, 12, 12
【问题讨论】:
-
请遵循minimal reproducible example 指南,包括一个有代表性但简短的示例,而不是指向另一个网站的链接。
标签: json nested export-to-csv jq