I have following xml file
<?xml version="1.0" encoding="UTF-8"?>
<root>
<UserData>
<User_Email>[email protected]</User_Email>
<User_Name>Louis Hebert</User_Name>
<User_State>South Dakota</User_State>
<id>item1</id>
</UserData>
<UserData>
<User_Email>[email protected]</User_Email>
<User_Name>David Lewis</User_Name>
<User_State>Connecticut</User_State>
<id>item2</id>
</UserData>
</root>
After converting to json the result is something like
{
"UserData": [
{
"User_Email": "[email protected]",
"User_Name": "Louis Hebert",
"User_State": "South Dakota",
"id": "item1"
},
{
"User_Email": "[email protected]",
"User_Name": "David Lewis",
"User_State": "Connecticut",
"id": "item2"
}
]
}
C# code which i am using
XmlDocument xmldoc = new XmlDocument();
string xml1 = @"D:\Visual_Codes\Xml_Files\Data.xml";
xmldoc.Load(xml1);
xmldoc.RemoveChild(xmldoc.FirstChild);
string js = JsonConvert.SerializeXmlNode(xmldoc, Newtonsoft.Json.Formatting.Indented, true);
Required Output
[
{
"User_Email": "[email protected]",
"User_Name": "Louis Hebert",
"User_State": "South Dakota",
"id": "item1"
},
{
"User_Email": "[email protected]",
"User_Name": "David Lewis",
"User_State": "Connecticut",
"id": "item2"
}
]
Summarising question Required a json file without array name after converting from xml to json
You can serialize each of the elements on its own and add the overhead by hand. If the structure won't change, this should be enough.