数据以这种形状开始:
[
{
date: "July 5, 2020"
name: "Calories"
symbol: "CALORIES"
value: 1,545.2
..,
},
{
date: "July 7, 2020"
name: "Total Carbs (g)"
symbol: "TOTAL_CARBS"
units: "g"
value: 45.2
..,
},
...
]
输出文件的预期形状.csv
应为:
--------------- 2020-07-05 2020-07-07 ...
Calories 1,545.2 1,6276.3 ...
Total Carbs (g) 45.2 56.9 ...
...
在传递给解析函数之前我应该如何转换数据?类似于:
const transformedQueryData = [
{
'date': 2020-07-05,
'CALORIES': 1,545.2,
'TOTAL_CARBS': 45.2,
},
{
'date': 2020-07-07,
'CALORIES': 1,6276.3,
'TOTAL_CARBS': 56.9,
}
];
OR
const transformedQueryData = [
{
2020-07-05: {
'CALORIES': 1,545.2,
'TOTAL_CARBS': 45.2,
}
},
{
2020-07-07: {
'CALORIES': 1,6276.3,
'TOTAL_CARBS': 56.9,
}
}
];
或者我可以使用 json2csv 实用程序和配置来按原样处理 queriedData 吗?