TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Suhas Kurse
NA
51
28.3k
Converting nested JSON string into csv
Jun 27 2019 11:50 PM
Will this code convert complex nested JSON into CSV
public
DataTable GetDataTableFromJsonString(
string
json)
{
var jsonLinq = JObject.Parse(json);
// Find the first array using Linq
var srcArray = jsonLinq.Descendants().Where(d => d
is
JArray).First();
var trgArray =
new
JArray();
foreach
(JObject row
in
srcArray.Children<JObject>())
{
var cleanRow =
new
JObject();
foreach
(JProperty column
in
row.Properties())
{
// Only include JValue types
if
(column.Value
is
JValue)
{
cleanRow.Add(column.Name, column.Value);
}
}
trgArray.Add(cleanRow);
}
return
JsonConvert.DeserializeObject<DataTable>(trgArray.ToString());
}
Reply
Answers (
3
)
Read text file and process calculation Impreva
Converting two Select Querys into One Query