I am converting a JSON file to a CSV file. The JSON has multiple nested objects. While converting, I am able to get all the values out of the JSON and into the CSV. However, all the values are being shown as one row with the same heading repeated multiple times. I am using CHOETL library.
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);
}
}
It shows the results as
- Record ID_0 Record ID_1 Record ID_2
- 123 456 789
Instead of as
- Record ID
- 123
- 456
- 789
Here is the JSON File
[
{
"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"
}
]
}
]
}
]