【发布时间】:2022-01-10 08:31:51
【问题描述】:
使用Miller 命令行工具,我想将带有标题的CSV 文件转换为JSON 数组。
目前我正在使用这个命令:mlr --icsv --ojson cat sample.csv > sample.json
输出的是 JSON,但不是数组格式。
这是示例 CSV 输入:
Keyword, Weight, Quantity
Apple, 10, 2345
Orange, 23, 467
Banana, 2345, 2345
这是我从米勒那里得到的输出:
{ "Keyword": "Apple", "Weight": 10, "Quantity": 2345 }
{ "Keyword": "Orange", "Weight": 23, "Quantity": 467 }
{ "Keyword": "Banana", "Weight": 2345, "Quantity": 2345 }
如您所见,此输出是 JSON Lines,而不是数组格式。
我希望 JSON 是一个数组,像这样:
[
{ "Keyword": "Apple", "Weight": 10, "Quantity": 2345 },
{ "Keyword": "Orange", "Weight": 23, "Quantity": 467 },
{ "Keyword": "Banana", "Weight": 2345, "Quantity": 2345 }
]
什么是正确的米勒命令?
【问题讨论】:
标签: miller