我有一个很大的数据表,我想将其转换为 json,并且不确定像 jq、mlr 或类似的工具是否能够执行这样的任务,而不必求助于我糟糕的 awk 技能。
样本表:
Balance_sheet for AAPL:
2023-09-30 2022-09-30 2021-09-30 2020-09-30
Treasury Shares Number 0.0 NaN NaN NaN
Ordinary Shares Number 15550061000.0 15943425000.0 16426786000.0 16976763000.0
首选输出:
{
"Balance_sheet for AAPL": {
"Treasury Shares Number": {
"2023-09-30": "0.0",
"2022-09-30": "NaN",
"2021-09-30": "NaN",
"2020-09-30": "NaN"
},
"Ordinary Shares Number": {
"2023-09-30": "15550061000.0",
"2022-09-30": "15943425000.0",
"2021-09-30": "16426786000.0",
"2020-09-30": "16976763000.0"
}
}
}
以下格式也可以使用,但不太理想:
{
"Balance_sheet for AAPL": {
"2023-09-30": {
"Treasury Shares Number": "0.0",
"Ordinary Shares Number": "15550061000.0"
},
"2022-09-30": {
"Treasury Shares Number": "NaN",
"Ordinary Shares Number": "15943425000.0"
},
"2021-09-30": {
"Treasury Shares Number": "NaN",
"Ordinary Shares Number": "16426786000.0"
},
"2020-09-30": {
"Treasury Shares Number": "NaN",
"Ordinary Shares Number": "16976763000.0"
}
}
}
有谁知道完成此任务的明智方法?