0
        //Convert CSV file to JSON
        var csv = new List<string[]>();
        var lines = csvResponseData.Split('\n');

        foreach (string line in lines)
            csv.Add(line.Split(','));

        var properties = lines[0].Split(',');

        var listObjResult = new List<Dictionary<string, string>>();

        for (int i = 1; i < lines.Length; i++)
        {
            if (lines[i].Length > 5)
            {
                var objResult = new Dictionary<string, string>();
                for (int j = 0; j < properties.Length; j++)
                {
                    if (properties.Length > j && csv.Count > i && csv[i].Length > j)
                    {
                        objResult.Add(properties[j], csv[i][j].Trim('\\'));
                    }
                }
                listObjResult.Add(objResult);
            }
            else
            {
                break;
            }
        }
        return JsonConvert.SerializeObject(listObjResult);
  • Currently I have this CSV File and when I am trying convert this to JSON object the Amount field data converted this '$2,651.98' to '$2' :

textbox78,CompanyName,CompanyDiscretionaryData,CustomerName,NachaID,EEDOriginalTransaction,textbox46,EEDofReturn,textbox49,textbox21,textbox33,textbox67,textbox68,textbox69,textbox70,textbox71 Processing Date - 7/6/2022,AgencyInsTEST, ,AgencyIns ,1234 ,PPD,Credit,7/7/2022,Checking Account,$250.99,4,$600.99,4,"$2,651.98",8,"$3,252.97"

Liza
  • 33
  • 5
  • Why not make your own proxy class, instance it fill it with data from the csv and then serialize it? – Josip Juros Jul 08 '22 at 13:21
  • Also your issue is you are using "," as delimeter, and also have "," for decimal values, get rid of one comma... either use a different delimeter or write your integers differently – Josip Juros Jul 08 '22 at 13:23

0 Answers0