Tag Archives: csv

Error Parsing from CSV file

Questions: I have a CSV file with 90 columns and I try to parse it with org.apache.commons.csv.CSVRecord. I get the first 3 columns perfectly, but when I want to get the 49th column’s content it returns the error Caused by: java.lang.IllegalArgumentException: Index for header ‘column49’ is 48 but CSVRecord only has 43 values! One part… Read More »

csv to json file format

Questions: I want to convert my csv file into .json format using c#. here what i have tried: var lines = @”text,intentName,entityLabels 1,2,null 2,1,null”.Replace(“\r”, “”).Split(‘\n’); var csv = lines.Select(l => l.Split(‘,’)).ToList(); var headers = csv[0]; var dicts = csv.Skip(1).Select(row => Enumerable.Zip(headers, row, Tuple.Create).ToDictionary(p => p.Item1, p => p.Item2)).ToArray(); string json = new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(dicts); Result1.Text =… Read More »

CsvHelper list of missing fields

Questions: Borrowing from this post – CSVHelper mandatory fields. Let’s say I have this code: public sealed class DataMapper : CsvClassMap<DataType> { public DataMapper() { Map(m => m.Field1).Name(“FirstField”); Map(m => m.Field2).ConvertUsing(m => { return 0; }); // required field Map(m => m.Field3).ConvertUsing(m => { return 1; }); // required field } } If I try… Read More »