From Json.NET documentation: http://james.newtonking.com/projects/json/help/?topic=html/ConvertingJSONandXML.htm

You can force a node to be rendered as an Array by adding the attribute json:Array='true' to the XML node you are converting to JSON. Also, you need to declare the json prefix namespace at the XML header xmlns:json='http://james.newtonking.com/projects/json' or else you will get an XML error stating that the json prefix is not declared.

The next example is provided by the documentation:

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

Generated output:

{
  "person": {
    "@id": "1",
    "name": "Alan",
    "url": "http://www.google.com",
    "role": [
      "Admin"
    ]
  }
}
Answer from Iván Pérez Gómez on Stack Overflow
Top answer
1 of 6
27

From Json.NET documentation: http://james.newtonking.com/projects/json/help/?topic=html/ConvertingJSONandXML.htm

You can force a node to be rendered as an Array by adding the attribute json:Array='true' to the XML node you are converting to JSON. Also, you need to declare the json prefix namespace at the XML header xmlns:json='http://james.newtonking.com/projects/json' or else you will get an XML error stating that the json prefix is not declared.

The next example is provided by the documentation:

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

Generated output:

{
  "person": {
    "@id": "1",
    "name": "Alan",
    "url": "http://www.google.com",
    "role": [
      "Admin"
    ]
  }
}
2 of 6
16

Giving my +1 to Iván Pérez Gómez and providing some code here to support his answer:

Add the required json.net namespace to the root node:

private static void AddJsonNetRootAttribute(XmlDocument xmlD)
    {
        XmlAttribute jsonNS = xmlD.CreateAttribute("xmlns", "json", "http://www.w3.org/2000/xmlns/");
        jsonNS.Value = "http://james.newtonking.com/projects/json";

        xmlD.DocumentElement.SetAttributeNode(jsonNS);
    }

And to add json:Array attribute to elements found by xpath:

private static void AddJsonArrayAttributesForXPath(string xpath, XmlDocument doc)
    {
        var elements = doc.SelectNodes(xpath);



        foreach (var element in elements)
        {
            var el = element as XmlElement;

            if (el != null)
            {

                var jsonArray = doc.CreateAttribute("json", "Array", "http://james.newtonking.com/projects/json");
                jsonArray.Value = "true";
                el.SetAttributeNode(jsonArray);
            }
        }
    }

Here is a sample of a single child node as a json array:

🌐
Newtonsoft
newtonsoft.com › json › help › html › ConvertXmlToJsonForceArray.htm
Convert XML to JSON and force array
This sample reads the json:Array="true" attribute in the XML and places its value in an array when converting the XML to JSON.
Discussions

JSON to XML converting with custom tag, JSON:array attribute is not added
But if I am using below mention JSON with ns3 tag and try to convert JSON to XML after converting it will not adding an attribute like xmlns:json='http://james.newtonking.com/projects/json' & json:Array='true' in converted XML. More on github.com
🌐 github.com
3
April 27, 2018
How do you represent a JSON array of strings? - Stack Overflow
This is all you need for valid JSON, right? ["somestring1", "somestring2"] More on stackoverflow.com
🌐 stackoverflow.com
What are the differences between using JSON arrays vs JSON objects? - Stack Overflow
The second form you show is actually not valid JSON, as each of the objects in the "thing" object would need some sort or property name to access it by. To answer your question, the difference is that in the first case, you would access the objects in "thing" using array access like obj.thing[0] ... More on stackoverflow.com
🌐 stackoverflow.com
Can a JSON file start with an array instead of an object?
Any valid JSON primitive is also a valid top-level JSON object. A JSON file could just as easily contain a single string, or even a single floating-point number, and still be valid. More on reddit.com
🌐 r/learnprogramming
18
11
May 25, 2024
🌐
GitHub
github.com › JamesNK › Newtonsoft.Json › issues › 661
Empty array serialization with json:Array='true' · Issue #661 · JamesNK/Newtonsoft.Json
September 22, 2015 - string xml = @"<person xmlns:json='http://james.newtonking.com/projects/json' id='1'> <role json:Array='true' /> </person>"; var doc = new XmlDocument(); doc.LoadXml(xml); var json = JsonConvert.SerializeXmlNode(doc); returns this json (please note role 'array', it has an empty object [{}] in it): Assert.AreEqual(@"{""person"":{""@id"":""1"",""role"":[{}]}}", json); However, we need this instead (we don't want empty object [] in the array) -and implemented a fix with unit tests passing-: Assert.AreEqual(@"{""person"":{""@id"":""1"",""role"":[]}}", json); Is there a way to achieve this in the current implementation?
Author   caglarcem
🌐
JSON Schema
json-schema.org › understanding-json-schema › reference › array
JSON Schema - array
A schema can ensure that each of the items in an array is unique. Simply set the uniqueItems keyword to true.
🌐
W3Schools
w3schools.com › js › js_json_arrays.asp
JSON Arrays
In JSON, array values must be of type string, number, object, array, boolean or null.
🌐
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 27, 2018 - 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
Find elsewhere
🌐
Oracle
docs.oracle.com › javaee › 7 › api › javax › json › JsonArray.html
JsonArray (Java(TM) EE 7 Specification APIs)
If the value at the specified position is JsonValue.TRUE this method returns true. If the value at the specified position is JsonValue.FALSE this method returns false. Otherwise this method returns the specified default value. ... Returns true if the value at the specified location in this ...
🌐
Leapcell
leapcell.io › blog › understanding-json-arrays-a-practical-guide
Understanding JSON Arrays: A Practical Guide | Leapcell
July 25, 2025 - JSON arrays store ordered, mixed-type data for structured information exchange.
🌐
W3Schools
w3schools.com › js › js_json_datatypes.asp
JSON Data Types
Values in JSON can be arrays. ... Values in JSON can be true/false.
🌐
Javatpoint
javatpoint.com › json-array
JSON Array - javatpoint
JSON Array for beginners and professionals with examples of JSON with java, json array of string, json array of numbers, json array of booleans, json srray of objects, json multidimentional array. Learn JSON array example with object, array, schema, encode, decode, file, date etc.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › what-is-json-array
What is JSON Array? - GeeksforGeeks
July 23, 2025 - For example, the array below has 5 elements in it each one of that is either true or false. ... Example: Here we assign a JSON Array of Booleans to the key boolean in jsonBooleanArray object.
🌐
JSONata
docs.jsonata.org › simple
Simple Queries · JSONata
true · JSON arrays are used when an ordered collection of values is required. Each value in the array is associated with an index (position) rather than a name, so in order to address individual values in an array, extra syntax is required to specify the index.
🌐
Oracle
docs.oracle.com › javame › 8.0 › api › json › api › com › oracle › json › JsonArray.html
JsonArray (JSON Documentation)
If the value at the specified position is JsonValue.TRUE this method returns true. If the value at the specified position is JsonValue.FALSE this method returns false. Otherwise this method returns the specified default value. ... Returns true if the value at the specified location in this ...
🌐
IBM
ibm.com › support › pages › creating-json-string-json-object-and-json-arrays-automation-scripts
Creating a JSON String from JSON Object and JSON Arrays in Automation Scripts
jsonStr = obj.serialize(True) return jsonStr # main part str = createJSONstring() print str · Code 2 - Creating a JSON Formatted String including JSON Array ·
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Learn_web_development › Core › Scripting › JSON
Working with JSON - Learn web development | MDN
As mentioned earlier, any JSON is a valid JavaScript literal (object, array, number, etc.). The converse is not true, though—not all JavaScript object literals are valid JSON.
🌐
JAXB
javaee.github.io › tutorial › jsonp001.html
Introduction to JSON
JSON defines only two data structures: objects and arrays. An object is a set of name-value pairs, and an array is a list of values. JSON defines seven value types: string, number, object, array, true, false, and null.