How can I convert the below XML to JSON
<?xml version="1.0" encoding="UTF-8" ?>
<data>
<attributes>
<product_no>PR1154</product_no>
</attributes>
<relationships>
<payables>
<data>
<attributes />
<relationships>
<payable>
<data>
<type>product-type</type>
<id>1254</id>
</data>
</payable>
</relationships>
</data>
</payables>
</relationships>
</data>
expect output
{ "data": { "attributes": { "product_no": "PR1154" }, "relationships": { "payables": { "data": [ { "attributes": {}, "relationships": { "payable": { "data": { "type": "product-type", "id": "1254" } } } } ] } } } }
what I am getting
{ "data": { "attributes": { "product_no": "PR1154" "relationships": { "payables": { "data": { "attributes": null, "relationships": { "payable": { "data": { "type": "product-type", "id": "1254" } } } } } } } } }
Dim postData As String = "<?xml version='1.0' encoding='UTF-8'?>" _
& "<data>" _
& "<attributes>" _
& "<product_no>PR1154</product_no>" _
& "<relationships>" _
& "<payables>" _
& "<data>" _
& "<attributes />" _
& "<relationships>" _
& "<payable>" _
& "<data>" _
& "<type>product-type</type>" _
& "<id>1254</id>" _
& "</data>" _
& "</payable>" _
& "</relationships>" _
& "</data>" _
& "</payables>" _
& "</relationships>" _
& "</attributes>" _
& "</data>"
Dim doc As XmlDocument = New XmlDocument()
doc.LoadXml(If(Me.TextBox1.Text = String.Empty, postData, Me.TextBox1.Text))
Dim jsonTextd = JsonConvert.SerializeObject(doc.FirstChild.NextSibling, Newtonsoft.Json.Formatting.Indented)
Me.TextBox1.Text = jsonTextd