I have an XML and when converting to JSON, all the values became string as below:
XML:
<root><deviceToEgressLocationDistance>600</deviceToEgressLocationDistance></root>
JSON:
{ "deviceToEgressLocationDistance": "600" }
while it should be
JSON:
{ "deviceToEgressLocationDistance": 600 }
below the code I am using but it converts everything to strings
XmlDocument doc = new XmlDocument();
doc.LoadXml(xmlString);
string jsonContent = JsonConvert.SerializeXmlNode(doc, Formatting.Indented, true);
I have checked the solution in Serialize Xml to Json using type attribute in c#
but I cannot manually parse every value as the xml file properties are changing every time so the next time it could be
XML:
<root><Location1>500.88</Location1><Location2>650</Location2></root>
The xml could have any structure including nesting properties.
Any ideas?
Update: After converting the XML to JSON, this JSON file is going to be the source to another system and if the JSON file has the wrong types like treating numbers as string or even DateTime as string, the subsystem fail to process the input source. So, I need to preserve the types in XML when converting to JSON