title: How to serialize Xml (from XLSX files) to Json ? C# .NET Json.Net
body: <p><em>I'm processing different kind of Xlsx files. <br>These files have multiples possibility of column eg 2 or 6 or even 7 Columns) <br>
  I read the Xml data inside using OpenXml and i would like to generate Json files from each worksheet. <br>
  Actually i'm able to read and to iterate through every worksheet but it seems weird when i try to convert it into Json format using Newtonsoft.Json</em></p>
  
  <p><br> 
  <strong>The Excel files is similare to this</strong> 
  <Br>
  Item 1 || Item 2 || Item 3 <Br>
  V1 || V2 || V3 <Br>
  V1 || V2 || V3 <Br>
  V1 || V2 || V3 <Br>
  <br> 
  <strong>But the generated JSON file is similare to this</strong> 
  <Br>
  [ <br> [Item 1 ,Item 2 ,Item 3]<br> [V1 ,V2 ,V3]<br> [V1 ,V2 ,V3]<br> [V1 ,V2 ,V3]<br>]</p>
  
  <p><br> 
  <strong>And i would like to format it like this</strong> 
  <Br></p>
  
  <p><Br>
  { <br> {"Item 1":"V1" ,"Item 2":"V2" ,"Item 3":"V3"}<br> {"Item 1":"V1" ,"Item 2":"V2" ,"Item 3":"V3"}<br> {"Item 1":"V1" ,"Item 2":"V2" ,"Item 3":"V3"}<br> }</p>
  
  <p>Here is my code : <br> <br></p>
  
  <p>using (SpreadsheetDocument excelDocument = SpreadsheetDocument.Open(file, false))
              {
                  var documentBody = excelDocument.WorkbookPart.Workbook;</p>
  
  <pre><code>            var sheets = documentBody.Sheets.Cast&lt;Sheet&gt;().ToList();
              sheets.ForEach(x =&gt; Console.WriteLine(String.Format("RelationshipId:{0}\n SheetName:{1}\n SheetId:{2}", x.Id.Value, x.Name.Value, x.SheetId.Value)));
  
              SharedStringTablePart sstpart = excelDocument.WorkbookPart.GetPartsOfType&lt;SharedStringTablePart&gt;().First();
              SharedStringTable sst = sstpart.SharedStringTable;
  
              Console.WriteLine("Worksheet count = {0}", documentBody.WorkbookPart.WorksheetParts.Count());
  
              foreach (var worksheetPart in documentBody.WorkbookPart.WorksheetParts)
              {
  
                  DocumentFormat.OpenXml.Spreadsheet.Worksheet sheet = worksheetPart.Worksheet;
  
                  var cells = sheet.Descendants&lt;Cell&gt;();
                  var rows = sheet.Descendants&lt;Row&gt;();
  
                  Console.WriteLine("Row count = {0}", rows.LongCount());
                  Console.WriteLine("Cell count = {0}", cells.LongCount());
                  var list = new List&lt;string[]&gt;();
                  foreach (Row row in rows)
                  {
                      Console.WriteLine("Row number: {0}", row.RowIndex);
                      list.Add(row.Elements&lt;Cell&gt;().Select(x =&gt; x.InnerText).ToArray());
                      foreach (Cell c in row.Elements&lt;Cell&gt;())
                      {
                          if (c.CellValue != null)
                          {
                              Console.WriteLine("Cell contents: {0}", c.CellValue.Text);
  
                          }
                      }
                  }
                  var i = JsonConvert.SerializeObject(list, Newtonsoft.Json.Formatting.Indented);
  
  
              }
          }
  </code></pre>