Вот вам go, я взял образец JSON из
https://docs.microsoft.com/en-us/graph/api/calendar-post-events?view=graph-rest-1.0&tabs=http
, использованный для его тестирования.
Вот код, используя ChoETL v1.2.0.2 (последний):
StringBuilder csv = new StringBuilder();
using (var w = new ChoCSVWriter(csv)
.WithFirstLineHeader()
)
{
using (var r = new ChoJSONReader(@"C:\Projects\GitHub\ChoETL\src\Test\ChoJSONReaderTest\sample41.json")
.WithField("id")
.WithField("iCalUId")
.WithField("isAllDay")
.WithField("isCancelled")
.WithField("isOrganizer")
.WithField("isOnlineMeeting")
.WithField("onlineMeetingProvider")
.WithField("type")
.WithField("startTime", jsonPath: "$.start.dateTime", isArray: false)
.WithField("endTime", jsonPath: "$.end.dateTime", isArray: false)
.WithField("location", jsonPath: "$.location.displayname")
.WithField("locationType", jsonPath: "$.location.locationType", isArray: false)
.WithField("organizer", jsonPath: "$.organizer.emailAddress.name", isArray: false)
.WithField("recurrence", jsonPath: "$.recurrence.pattern.type")
)
{
w.Write(r);
}
}
Console.WriteLine(csv.ToString());
Вывод:
id,iCalUId,isAllDay,isCancelled,isOrganizer,isOnlineMeeting,onlineMeetingProvider,type,startTime,endTime,location,locationType,organizer,recurrence
AAMkAGViNDU7zAAAAA7zAAAZb2ckAAA=,040000008200E641B4C,False,False,True,False,unknown,singleInstance,3/15/2019 12:00:00 PM,3/15/2019 2:00:00 PM,,default,Megan Bowen,
ОБНОВЛЕНИЕ: Вот обновленный код для изменения порядка полей и получения количества участников
StringBuilder csv = new StringBuilder();
using (var w = new ChoCSVWriter(csv)
.WithFirstLineHeader()
)
{
using (var r = new ChoJSONReader(@"C:\Projects\GitHub\ChoETL\src\Test\ChoJSONReaderTest\sample41.json")
.WithField("startTime", jsonPath: "$.start.dateTime", isArray: false)
.WithField("endTime", jsonPath: "$.end.dateTime", isArray: false)
.WithField("id")
.WithField("iCalUId")
.WithField("isAllDay")
.WithField("isCancelled")
.WithField("isOrganizer")
.WithField("isOnlineMeeting")
.WithField("onlineMeetingProvider")
.WithField("type")
.WithField("location", jsonPath: "$.location.displayname")
.WithField("locationType", jsonPath: "$.location.locationType", isArray: false)
.WithField("organizer", jsonPath: "$.organizer.emailAddress.name", isArray: false)
.WithField("recurrence", jsonPath: "$.recurrence.pattern.type")
.WithField("attendees", jsonPath: "$.attendees[*]", valueConverter: o => ((IList)o).Count)
)
{
w.Write(r);
}
}
Console.WriteLine(csv.ToString());