How to parse CSV into JSON when CSV contains quoted strings containing commas
<p>Currently I have CSV along these lines :</p>

<pre><code>"NAME","AGE","SEX"
"FRED, JONES","45","MALE"
"SALLY, SMITH","60","FEMALE"
</code></pre>

<p>And I use the following code to serialize it into JSON :</p>

<pre><code>var linesCSV = System.IO.File.ReadAllLines(targetFile); //target file is the csv

var csv = linesCSV.Select(l =&gt; l.Split(',')).ToList();

var headers = csv[0];
var dicts = csv.Skip(1).Select(row =&gt; Enumerable.Zip(headers, row, System.Tuple.Create).ToDictionary(p =&gt; p.Item1, p =&gt; p.Item2)).ToArray();

string json = new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(dicts);

jsWrtr.WriteLine(json);
</code></pre>

<p>This gets outputted like so :</p>

<pre><code>[{
  "\NAME\"" : "\"FRED\"",
  "\AGE\"" : "\"JONES\"",
  "\SEX\"" : "\"45\""
},
{
  "\NAME\"" : "\"SALLY\"",
  "\AGE\"" : "\"SMITH\"",
  "\SEX\"" : "\"60\""
}]
</code></pre>

<p>You can see the <code>NAME</code> gets split up and the second part, part after the comma, gets put into the next field.</p>

<p>This is obviously because of the comma inbetween, but my question is how do I just parse the CSV so it outputs the following :</p>

<pre><code>[{
   "NAME" : "FRED, JONES",
   "AGE" : "45",
   "SEX" : "MALE"
 },
 {
   "NAME" : "SALLY, SMITH",
   "AGE" : "60",
   "SEX" : "FEMALE"
 }]
</code></pre>