我正在将 JSON 文件转换为 CSV 文件。JSON 具有多个嵌套对象。转换时,我能够将所有值从 JSON 中获取并放入 CSV 中。但是,所有值都显示为一行,且同一标题重复多次。我正在使用 CHOETL 库。
using (var csv = new ChoCSVWriter("file1.csv").WithFirstLineHeader().WithDelimiter(","))
{
using (var json = new ChoJSONReader("file2.json")
.WithField("RecordID", jsonPath: "$..Events[*].RecordId")
.WithField("RecordType", jsonPath: "$..Events[*].RecordType")
.WithField("EventDate", jsonPath: "$..Events[*].EventDate")
{
csv.Write(json);
}
}
结果显示为
记录 ID_0 记录 ID_1 记录 ID_2
123 456 789
而不是作为
记录ID
123
456
789
这是 JSON 文件
[
{
"Id": "3e399241",
"IdLineage": [
"sfdsfdsfs",
"sdfdsfdsf"
],
"Individuals": [
{
"Id": "1232112",
"IdLineage": [
"fdsfsd1"
],
"Events": [
{
"RecordId": "2132121321",
"RecordType": "SALE",
"EventDate": "2016-01-04T05:00:00Z"
},
{
"RecordId": "123213212",
"RecordType": "SALE",
"EventDate": "2012-07-16T04:00:00Z"
}
]
},
{
"Id": "ssf2112",
"IdLineage": [],
"Events": [
{
"RecordId": "123213ds21",
"RecordType": "ACXIOMRECORD",
"EventDate": "2017-12-17T03:33:54.875Z"
}
]
},
{
"Id": "asadsad",
"IdLineage": [],
"Events": [
{
"RecordId": "213213sa21",
"RecordType": "SALE",
"EventDate": "2018-03-09T05:00:00Z"
}
]
}
]
}
]
汪汪一只猫
相关分类