title: F# Convert CsvFile to Json object array
body: <p>Trying to learn F# and got stuck when trying to find a better approach of converting a csv file to a json array where each row + header is a json object in that array.</p>
  <p>After some trial and error I finally caved and went for an ugly approach with mutable list and map. Are there any better ways this can be implemented?</p>
  <pre><code>let csvFileToJsonList (csvFile: FSharp.Data.CsvFile) =
      let mutable tempList = List.empty&lt;Map&lt;string,string&gt;&gt;
      let heads =
          match csvFile.Headers with
          | Some h -&gt; h
          | None -&gt; [|&quot;Missing&quot;|] // what to do here?
      let nbrOfColumns = csvFile.NumberOfColumns
      for row in csvFile.Rows do
          let columns = row.Columns
          let mutable tempMap = Map.empty&lt;string,string&gt;
          for i = 0 to nbrOfColumns-1  do
                  tempMap &lt;- tempMap.Add(heads.[i], columns.[i])
          tempList &lt;- tempMap :: tempList
      System.Text.Json.JsonSerializer.Serialize(tempList)
  </code></pre>
  <p>This outputs the following which is the goal:</p>
  <pre><code>    [
          {
              &quot;Header1&quot;: &quot;Row1Val1&quot;,
              &quot;Header2&quot;: &quot;Row1Val2&quot;,
              &quot;Header3&quot;: &quot;Row1Val3&quot;,
              &quot;Header4&quot;: &quot;Row1Val4&quot;,
              &quot;Header5&quot;: &quot;Row1Val5&quot;
          },
          {
              &quot;Header1&quot;: &quot;Row2Val1&quot;,
              &quot;Header2&quot;: &quot;Row2Val2&quot;,
              &quot;Header3&quot;: &quot;Row2Val3&quot;,
              &quot;Header4&quot;: &quot;Row2Val4&quot;,
              &quot;Header5&quot;: &quot;Row2Val5&quot;
          }
      ]
  </code></pre>