using System.Collections.Generic;
public static void Main()
List<OrgChart> newOrgChartData = new List<OrgChart>();
newOrgChartData.Add(new OrgChart{name = "A", coordination = "1"});
newOrgChartData.Add(new OrgChart{name = "B", coordination = "1.1"});
newOrgChartData.Add(new OrgChart{name = "C", coordination = "1.2"});
newOrgChartData.Add(new OrgChart{name = "D", coordination = "1.1.1"});
newOrgChartData.Add(new OrgChart{name = "E", coordination = "1.1.2"});
newOrgChartData.Add(new OrgChart{name = "F", coordination = "1.1.1.1"});
var getOrgChart = (from root in newOrgChartData
where root.coordination.Length == 1
name = root.coordination,
children = newOrgChartData.Where(o => o.coordination.Count(c => c == '.') == 1
&& o.coordination.StartsWith(root.coordination)).ToList()
.Select(levelTwo => new GetOrgChart
name = levelTwo.coordination,
children = newOrgChartData.Where(o => o.coordination.Count(c => c == '.') == 2
&& o.coordination.StartsWith(levelTwo.coordination)).ToList()
.Select(levelThree => new GetOrgChart
name = levelThree.coordination
string json = JsonConvert.SerializeObject(getOrgChart);
public string name {get; set;}
public string coordination {get; set;}
public class GetOrgChart {
public string name {get; set;}
public List<GetOrgChart> children {get; set;}