I've used the online converters but they don't do exactly what I need them to do so I was hoping to write a small program to get it to convert the csv to json in the exact format I need. So lets start with the csv file:
Id,Sea,First,Last,Team,Coll,Num,Age,Hgt,Wgt,Pos,Attr/Str,Attr/Agi,Attr/Arm,Attr/Spe,Attr/Han,Attr/Intel,Attr/Acc,Attr/PBl,Attr/RBl,Attr/Tck,Attr/KDi,Attr/KAc,Attr/End,Per/Lea,Per/Wor,Per/Com,Per/TmPl,Per/Spor,Per/Soc,Per/Mny,Per/Sec,Per/Loy,Per/Win,Per/PT,Per/Home,Per/Mkt,Per/Mor,Skills/QB,Flg,Trait,Skills/RB,Skills/FB,Skills/G,Skills/T,Skills/C,Skills/WR,Skills/TE,Skills/CB,Skills/SS,Skills/FS,Skills/DE,Skills/LB,Skills/DT,Skills/K,Skills/P
,2018,David,Bush,,Stanford,19,21,76,212,QB,68,55,89,70,31,96,99,1,5,24,1,1,74,34,71,62,33,76,88,15,15,40,14,31,33,9,94,,,,,,,,,,,,,,,,,,
Now this is the output in json:
{
"Players": [{
"Id": 2938,
"Sea": 2018,
"First": "Harold",
"Last": "Dalton",
"Team": "0",
"Coll": "Western Kentucky",
"Num": 87,
"Age": 20,
"Hgt": 76,
"Wgt": 224,
"Pos": "WR",
"Attr": {
"Str": 59,
"Agi": 79,
"Arm": 1,
"Spe": 87,
"Han": 77,
"Intel": 38,
"Acc": 1,
"PBl": 1,
"RBl": 11,
"Tck": 21,
"KDi": 1,
"KAc": 1,
"End": 58
},
"Per": {
"Lea": 62,
"Wor": 76,
"Com": 61,
"TmPl": 58,
"Spor": 62,
"Soc": 94,
"Mny": 92,
"Sec": 32,
"Loy": 31,
"Win": 68,
"PT": 90,
"Home": 36,
"Mkt": 45,
"Mor": 70
},
"Skills": {
"WR": 53,
"TE": 31
},
"Flg": "None",
"Trait": "None"
},
Yes its a different player, that's not the point here :)
And here's the code I have so far, without the conversion process...
SaveFileDialog sfd = new SaveFileDialog();
OpenFileDialog ofd = new OpenFileDialog();
public static string fileName;
private void open_btn_Click(object sender, EventArgs e)
{
ofd.Filter = "CSV Files (.csv)|*.csv";
ofd.Title = "Open CSV File";
if (ofd.ShowDialog() == DialogResult.OK)
{
richTextBox1.LoadFile(ofd.FileName, RichTextBoxStreamType.PlainText);
fileName = ofd.FileName;
open_label.Text = System.IO.Path.GetFileName(fileName);
}
}
private void save_btn_Click(object sender, EventArgs e)
{
sfd.Filter = "JSON Files (.json)|*.json";
sfd.Title = "Save JSON File";
if (sfd.ShowDialog() == DialogResult.OK)
{
//how do I convert the loaded .csv file into the json format below???
}
}
public class Rootobject
{
public Player[] Players { get; set; }
}
public class Player
{
public int Id { get; set; }
public int Sea { get; set; }
public string First { get; set; }
public string Last { get; set; }
public string Team { get; set; }
public string Coll { get; set; }
public int Num { get; set; }
public int Age { get; set; }
public int Hgt { get; set; }
public int Wgt { get; set; }
public string Pos { get; set; }
public Attr Attr { get; set; }
public Per Per { get; set; }
public Skills Skills { get; set; }
public string Flg { get; set; }
public string Trait { get; set; }
}
public class Attr
{
public int Str { get; set; }
public int Agi { get; set; }
public int Arm { get; set; }
public int Spe { get; set; }
public int Han { get; set; }
public int Intel { get; set; }
public int Acc { get; set; }
public int PBl { get; set; }
public int RBl { get; set; }
public int Tck { get; set; }
public int KDi { get; set; }
public int KAc { get; set; }
public int End { get; set; }
}
public class Per
{
public int Lea { get; set; }
public int Wor { get; set; }
public int Com { get; set; }
public int TmPl { get; set; }
public int Spor { get; set; }
public int Soc { get; set; }
public int Mny { get; set; }
public int Sec { get; set; }
public int Loy { get; set; }
public int Win { get; set; }
public int PT { get; set; }
public int Home { get; set; }
public int Mkt { get; set; }
public int Mor { get; set; }
}
public class Skills
{
public int G { get; set; }
public int T { get; set; }
public int C { get; set; }
public int WR { get; set; }
public int TE { get; set; }
public int DT { get; set; }
public int DE { get; set; }
public int LB { get; set; }
public int SS { get; set; }
public int CB { get; set; }
public int FS { get; set; }
public int RB { get; set; }
public int FB { get; set; }
public int QB { get; set; }
public int K { get; set; }
public int P { get; set; }
}