Share Link
Copied to clipboard
Embed on Your Page
Copied to clipboard
We Stand with Ukraine
[Fork] https://stackoverflow.com/questions/53783053/force-root-xml-element-to-be-array-on-json-conversion by dbc_MinLength
Environment version: 4.0.30319.42000
Json.NET version: Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed

Input XML: 
<person xmlns:json="http://james.newtonking.com/projects/json" id="1" json:Array="true">
  <name>Alan</name>
  <url>http://www.google.com</url>
  <role json:Array="true">Admin</role>
</person>

Result of converting XDocument to JSON: 
{
  "person": [
    {
      "@id": "1",
      "name": "Alan",
      "url": "http://www.google.com",
      "role": [
        "Admin"
      ]
    }
  ]
}

Result of converting XDocument.Root to JSON: 
{
  "person": {
    "@id": "1",
    "name": "Alan",
    "url": "http://www.google.com",
    "role": [
      "Admin"
    ]
  }
}

Result of converting XmlDocument to JSON: 
{
  "person": [
    {
      "@id": "1",
      "name": "Alan",
      "url": "http://www.google.com",
      "role": [
        "Admin"
      ]
    }
  ]
}

Result of converting XmlDocument.DocumentElement to JSON: 
{
  "person": {
    "@id": "1",
    "name": "Alan",
    "url": "http://www.google.com",
    "role": [
      "Admin"
    ]
  }
}
Cached Result
Last Run: 2:25:46 pm
Compile: 0.22s
Execute: 0.235s
Memory: 1.64Mb
CPU: 0.25s