DeserializeXmlNode() doesn't really have a way to customize the way it does its JSON to XML conversion. To get the result you want using that method, you will either have to manipulate the JSON before converting it to XML, or manipulate the XML afterwards.

In this case, I think it might be easier to use Json.Net's LINQ-to-JSON API to build the XML directly from the JSON in the shape you want. You can do it like this:

var ja = JArray.Parse(jsonResult);
var xml = new XDocument(
    new XElement("cars", 
        ja.Select(c => 
            new XElement("car",
                new XElement("features", 
                    c["car"]["features"].Select(f => 
                        new XElement("feature", 
                            new XElement("code", (string)f["code"])
                        )
                    )
                )
            )
        )
    )
);

Console.WriteLine(xml.ToString());

Fiddle: https://dotnetfiddle.net/fxxQnL

Answer from Brian Rogers on Stack Overflow
Top answer
1 of 2
2

DeserializeXmlNode() doesn't really have a way to customize the way it does its JSON to XML conversion. To get the result you want using that method, you will either have to manipulate the JSON before converting it to XML, or manipulate the XML afterwards.

In this case, I think it might be easier to use Json.Net's LINQ-to-JSON API to build the XML directly from the JSON in the shape you want. You can do it like this:

var ja = JArray.Parse(jsonResult);
var xml = new XDocument(
    new XElement("cars", 
        ja.Select(c => 
            new XElement("car",
                new XElement("features", 
                    c["car"]["features"].Select(f => 
                        new XElement("feature", 
                            new XElement("code", (string)f["code"])
                        )
                    )
                )
            )
        )
    )
);

Console.WriteLine(xml.ToString());

Fiddle: https://dotnetfiddle.net/fxxQnL

2 of 2
0

With Cinchoo ETL - an open source library, you can do the Xml to Json easily with few lines of code

string json = @"
[
    {
        ""car"": {
            ""features"": [{
                ""code"": ""1""
            }, {
                ""code"": ""2""
            }]
        }
    },
    {
        ""car"": {
            ""features"": [{
                ""code"": ""3""
            }, {
                ""code"": ""2""
            }]
        }
    }
]";
StringBuilder sb = new StringBuilder();
using (var p = ChoJSONReader.LoadText(json))
{
    using (var w = new ChoXmlWriter(sb)
        .Configure(c => c.RootName = "cars")
        //.Configure(c => c.IgnoreRootName = true)
        .Configure(c => c.IgnoreNodeName = true)
        )
    {
        w.Write(p);
    }
}
Console.WriteLine(sb.ToString());

Output:

<cars>
  <car>
    <features>
      <feature>
        <code>1</code>
      </feature>
      <feature>
        <code>2</code>
      </feature>
    </features>
  </car>
  <car>
    <features>
      <feature>
        <code>3</code>
      </feature>
      <feature>
        <code>2</code>
      </feature>
    </features>
  </car>
</cars>

Checkout CodeProject article for some additional help.

Disclaimer: I'm the author of this library.

🌐
FreeFormatter
freeformatter.com › json-to-xml-converter.html
Free Online JSON to XML Converter - FreeFormatter.com
This free online tool lets you convert a JSON into an XML file and formats the output with your chosen indentation
People also ask

How to use the Convert JSON Array to XML Online for free?
Upload your JSON file, paste data, or extract from web pages using our free online table converter. Convert JSON to XML instantly with real-time preview and advanced editing. This JSON to XML converter lets you copy or download your XML output right away.
🌐
tableconvert.com
tableconvert.com › home › convert json array to xml online
Convert JSON Array to XML Online - Table Convert
What is JSON Array format?
JSON (JavaScript Object Notation) is the standard table data format for modern web applications, REST APIs, and microservice architectures. Its clear structure and efficient parsing make it widely used in front-end and back-end data interaction, configuration file storage, and NoSQL databases. Supports nested objects, array structures, and multiple data types, making it indispensable table data for modern software development.
🌐
tableconvert.com
tableconvert.com › home › convert json array to xml online
Convert JSON Array to XML Online - Table Convert
What is XML format?
XML (eXtensible Markup Language) is the standard format for enterprise-level data exchange and configuration management, with strict syntax specifications and powerful validation mechanisms. Widely used in web services, configuration files, document storage, and system integration. Supports namespaces, schema validation, and XSLT transformation, making it important table data for enterprise applications.
🌐
tableconvert.com
tableconvert.com › home › convert json array to xml online
Convert JSON Array to XML Online - Table Convert
🌐
Table Convert
tableconvert.com › home › convert json array to xml online
Convert JSON Array to XML Online - Table Convert
July 28, 2025 - Supports automatic recognition and parsing of object arrays, nested structures, and complex data types. The tool intelligently validates JSON syntax and provides error prompts. ... Edit data using our advanced online table editor with professional features. Supports deleting empty rows, removing duplicates, data transposition, sorting, regex find & replace, and real-time preview. All changes automatically convert to XML format with precise, reliable results.
🌐
Oxygen XML
oxygenxml.com › doc › ug-editor › topics › convert-JSON-to-XML-x-tools.html
JSON to XML Converter
If the JSON document has more than one property on the first level, the converted XML document will have an additional root element called <JSON>. ... <?xml version="1.0" encoding="UTF-8"?> <JSON> <personnel> <person> <name>Boss</name> </person> <person> <name>Worker</name> </person> </personnel> <id>personnel-id</id> </JSON> If the JSON document is an array, the converted XML document will have a root element called <array> and for each item within the array, another <array> is created.
🌐
Convertjson
convertjson.com › json-to-xml.htm
JSON To XML Converter
Use this tool to convert JSON into XML format. New- Now supports JSONLines. Enter your JSON or JSONLines data below and Press the Convert button. The output will display below the Convert button.
Find elsewhere
🌐
JSON Formatter
jsonformatter.org › json-to-xml
Best JSON to XML Converter
JSON to XML is very unique tool for convert JOSN to XML and allows to download, save, share and print JSON to XML data.. JSON to XML support URL linking for sharing json. i.e. https://jsonformatter.org/json-to-xml/?url=https://gist.githubusercontent.com/jimmibond/9205480889e19c0de347/raw/sample.json · No. It's not required to save and share code. If JSON data is saved without login, it will become public. To make json data private please login and save the links.
🌐
GitHub
github.com › JamesNK › Newtonsoft.Json › issues › 1734
JSON to XML converting with custom tag, JSON:array attribute is not added · Issue #1734 · JamesNK/Newtonsoft.Json
April 29, 2018 - {"Test_Service" : {"fname":"mark","lname":"joye","CarCompany":"saab","CarNumber":"9741","IsInsured":"true","safty":["ABS","AirBags","childdoorlock"],"CarDescription":"test Car","collections":[{"XYZ":"1","PQR":"11","contactdetails":[{"contname":"DOM","contnumber":"8787"},{"contname":"COM","contnumber":"4564","addtionaldetails":[{"description":"54657667"}]},{"contname":"gf","contnumber":"123","addtionaldetails":[{"description":"123"}]}]}]}} While i am converting above JSON into XML it will add an attribute like xmlns:json='http://james.newtonking.com/projects/json' & json:Array='true' in XML.
Author   vatsaldesai
Top answer
1 of 12
499

Yes. Using the JsonConvert class which contains helper methods for this precise purpose:

// To convert an XML node contained in string xml into a JSON string   
XmlDocument doc = new XmlDocument();
doc.LoadXml(xml);
string jsonText = JsonConvert.SerializeXmlNode(doc);

// To convert JSON text contained in string json into an XML node
XmlDocument doc = JsonConvert.DeserializeXmlNode(json);

Documentation here: Converting between JSON and XML with Json.NET

2 of 12
60

Yes, you can do it (I do) but Be aware of some paradoxes when converting, and handle appropriately. You cannot automatically conform to all interface possibilities, and there is limited built-in support in controlling the conversion- many JSON structures and values cannot automatically be converted both ways. Keep in mind I am using the default settings with Newtonsoft JSON library and MS XML library, so your mileage may vary:

XML -> JSON

  1. All data becomes string data (for example you will always get "false" not false or "0" not 0) Obviously JavaScript treats these differently in certain cases.
  2. Children elements can become nested-object {} OR nested-array [ {} {} ...] depending if there is only one or more than one XML child-element. You would consume these two differently in JavaScript, etc. Different examples of XML conforming to the same schema can produce actually different JSON structures this way. You can add the attribute json:Array='true' to your element to workaround this in some (but not necessarily all) cases.
  3. Your XML must be fairly well-formed, I have noticed it doesn't need to perfectly conform to W3C standard, but 1. you must have a root element and 2. you cannot start element names with numbers are two of the enforced XML standards I have found when using Newtonsoft and MS libraries.
  4. In older versions, Blank elements do not convert to JSON. They are ignored. A blank element does not become "element":null

A new update changes how null can be handled (Thanks to Jon Story for pointing it out): https://www.newtonsoft.com/json/help/html/T_Newtonsoft_Json_NullValueHandling.htm

JSON -> XML

  1. You need a top level object that will convert to a root XML element or the parser will fail.
  2. Your object names cannot start with a number, as they cannot be converted to elements (XML is technically even more strict than this) but I can 'get away' with breaking some of the other element naming rules.

Please feel free to mention any other issues you have noticed, I have developed my own custom routines for preparing and cleaning the strings as I convert back and forth. Your situation may or may not call for prep/cleanup. As StaxMan mentions, your situation may actually require that you convert between objects...this could entail appropriate interfaces and a bunch of case statements/etc to handle the caveats I mention above.

🌐
Online XML Tools
onlinexmltools.com › convert-json-to-xml
Convert JSON to XML - Online XML Tools
Free online JSON to XML converter. Just paste your JSON in the input form below and it will automatically get converted to XML. There are no ads, popups or nonsense, just an awesome JSON to XML transformer. Load JSON, get XML. Created for programmers by programmers from team Browserling.
🌐
Newtonsoft
newtonsoft.com › json › help › html › ConvertJsonToXml.htm
Convert JSON to XML
This sample converts JSON to XML. ... string json = @"{ '@Id': 1, 'Email': 'james@example.com', 'Active': true, 'CreatedDate': '2013-01-20T00:00:00Z', 'Roles': [ 'User', 'Admin' ], 'Team': { '@Id': 2, 'Name': 'Software Developers', 'Description': 'Creators of fine software products and services.'
🌐
Code Maze
code-maze.com › home › how to convert json to xml or xml to json in c#
How to Convert JSON to XML or XML to JSON in C# - Code Maze
September 6, 2022 - The highlighted lines are all we need to change in the XML. We add a namespace for Newtonsoft’s JSON schema in the root element. This allows us to set a flag attribute json:Array to true on the target element (Stars tag in our case). During serialization this attribute instructs the converter to ...
🌐
Google
discuss.google.dev › google cloud › apigee
how to convert a JSON array to XML - Apigee - Google Developer forums
March 7, 2021 - first, use the extract variable policy to get the json array and next on the same use json to xml policy to get the xml presentation. ... You can extract either all of the JSON payload or some jsonpath derived subset into a flow variable using ...
🌐
Newtonsoft
newtonsoft.com › json › help › html › ConvertingJSONandXML.htm
Converting between JSON and XML
Json.NET supports converting JSON to XML and vice versa using the XmlNodeConverter. Elements, attributes, text, comments, character data, processing instructions, namespaces, and the XML declaration are all preserved when converting between the two. The only caveat is that it is possible to lose the order of differently named nodes at the same level when they are grouped together into an array...
🌐
ReqBin
reqbin.com › json-to-xml
Online JSON to XML Converter
August 31, 2023 - The JSON to XML converter is simple and easy to use, with minimal configuration options. Enter JSON data and click "Convert JSON to XML" to convert JSON strings to XML data online and see the result.
🌐
Withdata Software
withdata.com › blog › datafileconverter › convert-json-array-to-xml.html
Convert JSON array to XML file
June 18, 2025 - Download DataFileConverter Windows 64 bit Windows 32 bit Linux .deb (For Debian, Ubuntu) 64 bit Linux .rpm (For Red Hat, Fedora, SUSE) 64 bit MacOS 64 bit · Choose JSON array file -> Set XML file -> Convert JSON array to XML
🌐
Teleport
goteleport.com › resources › tools › json-to-xml-converter
JSON to XML Converter | Instant JSON to XML Conversion | Teleport
Convert JSON data to XML instantly with our free online tool. Simplify your data conversions with fast, accurate processing.