Infer Arrays of Scalar Values from XML
See how repeated simple elements containing only text content produce arrays of scalar types (strings, numbers) in the JSON Schema.
Detailed Explanation
Scalar Arrays from Repeated Text Elements
Not all XML arrays contain complex objects. Sometimes repeated elements hold simple text values. The converter handles this by producing an array with a scalar item type.
Example XML
<config>
<name>My App</name>
<tags>
<tag>frontend</tag>
<tag>react</tag>
<tag>typescript</tag>
</tags>
<ports>
<port>3000</port>
<port>8080</port>
<port>443</port>
</ports>
<features>
<enabled>true</enabled>
<enabled>false</enabled>
<enabled>true</enabled>
</features>
</config>
Generated Schema
{
"type": "object",
"properties": {
"config": {
"type": "object",
"properties": {
"name": { "type": "string" },
"tags": {
"type": "object",
"properties": {
"tag": {
"type": "array",
"items": { "type": "string" }
}
}
},
"ports": {
"type": "object",
"properties": {
"port": {
"type": "array",
"items": { "type": "integer" }
}
}
},
"features": {
"type": "object",
"properties": {
"enabled": {
"type": "array",
"items": { "type": "boolean" }
}
}
}
}
}
}
}
Type Preservation in Arrays
Each scalar array preserves its inferred type. The <tag> elements produce a string array, <port> elements produce an integer array, and <enabled> elements produce a boolean array.
Mixed-Type Arrays
If repeated elements contain different types:
<values>
<value>42</value>
<value>hello</value>
</values>
The item type becomes a union: ["integer", "string"].
Wrapper Elements
Notice that XML often uses a wrapper element for collections (<tags> wrapping <tag>, <ports> wrapping <port>). The schema reflects this structure. The wrapper becomes an object, and the repeated child becomes an array property within it.
Use Case
When processing XML configuration files, API responses with simple lists, or any XML that represents collections of primitive values. This pattern is extremely common in configuration formats like Maven POM dependencies, Spring beans, and Android resources.