static void Main(string[] args) { /*Console.WriteLine( StateCensusAnalyser.GetRecordsFromCSVFile(path)); * Console.WriteLine(CSVStateCensus.ToGetDataFromCSVFileUsigEnumerator(path));*/ // var fi = CSVStateCensus.ToGetDataFromCSVFile(path); //Console.WriteLine(fi); /* string stateCensusData = StateCensusAnalyser.SortStateCodeandWriteInJson(CsvStateCensuspath, jsonCsvStateCensuspath, "State"); * string stateCode = StateCensusAnalyser.SortStateCodeandWriteInJson(CsvStateCodePath, jsonCsvStateCodepath, "StateCode"); * * Console.WriteLine(stateCensusData); * Console.WriteLine(stateCode); */ string val = CSVOperations.RetriveFirstDataOnKey(jsonCsvStateCensuspath, "State"); string lat = CSVOperations.RetriveLastDataOnKey(jsonCsvStateCensuspath, "State"); Console.WriteLine(val); Console.WriteLine(lat); }
public static string SortCSVFileWriteInJsonAndReturnFirstData(string filePath, string jsonFilepath, string key) { string re = File.ReadAllText(filePath); StringBuilder sb = new StringBuilder(); using (var p = ChoCSVReader.LoadText(re) .WithFirstLineHeader() ) { using (var w = new ChoJSONWriter(sb)) w.Write(p); } File.WriteAllText(jsonFilepath, sb.ToString()); JArray arr = CSVOperations.SortJsonBasedOnKey(jsonFilepath, key); var jsonArr = JsonConvert.SerializeObject(arr, Formatting.Indented); File.WriteAllText(jsonFilepath, jsonArr); return(CSVOperations.RetriveFirstDataOnKey(jsonFilepath, key)); }
/// <summary> ///Method for sort First value from json file /// </summary> /// <param name="path"> State Code data path </param> /// <param name="jsonFilepath"> Delimiter </param> /// <param name="key"> Header </param> /// <returns> Sort the file and return first value </returns> public static string SortCSVFileWriteInJsonAndReturnFirstData(string path, string jsonFilepath, string key) { //create a object to read file string csvfile = File.ReadAllText(path); StringBuilder json = new StringBuilder(); //read a csv file using (var p = ChoCSVReader.LoadText(csvfile) .WithFirstLineHeader() ) { //write json file using (var w = new ChoJSONWriter(json)) w.Write(p); } File.WriteAllText(jsonFilepath, json.ToString()); JArray arr = CSVOperations.SortJsonBasedOnKey(jsonFilepath, key); //convert into json format var jsonArr = JsonConvert.SerializeObject(arr, Formatting.Indented); File.WriteAllText(jsonFilepath, jsonArr); return(CSVOperations.RetriveFirstDataOnKey(jsonFilepath, key)); }