title: vb.net datatable Serialize to json
body: <p>I have this kind of table:</p>
  
  <p><img src="https://i.stack.imgur.com/B1ShR.png" alt=""> </p>
  
  <p>I need to get this JSON (of course order could be any, structure/tree is most important):</p>
  
  <p><img src="https://i.stack.imgur.com/Q16ui.png" alt=""></p>
  
  <p>Data table can change, so serialization should be dynamic. I am working with vb.net and used this code:</p>
  
  <pre><code> Public Function GetJson() As String
          Dim dt As New System.Data.DataTable
          dt = CreateDataTable() 'here I retrive data from oracle DB
          Dim serializer As New System.Web.Script.Serialization.JavaScriptSerializer()
          Dim packet As New List(Of Dictionary(Of String, Object))()
          Dim row As Dictionary(Of String, Object) = Nothing
          For Each dr As DataRow In dt.Rows
              row = New Dictionary(Of String, Object)()
              For Each dc As DataColumn In dt.Columns
                  row.Add(dc.ColumnName.Trim(), dr(dc))
              Next
              packet.Add(row)
          Next
          Return serializer.Serialize(packet)
      End Function
  </code></pre>
  
  <p>But this code returns me bad json: <code>[{"NAME":"city","PARENT":"address","VALUE":"has child"},{"NAME":"coordinates","PARENT":"address","VALUE":"has child"},{"NAME":"street","PARENT":"address","VALUE":"has child"}.......</code></p>
  
  <p>Can someone help me out in here?</p>