Infer Schema from XML Configuration Files

Generate JSON Schema from typical XML configuration files with mixed nesting, optional sections, and typed values for validation purposes.

Complex Structures

Detailed Explanation

XML Configuration Files to JSON Schema

XML configuration files are one of the most common use cases for schema inference. They typically combine nested sections, typed values, optional elements, and sometimes attributes for metadata.

Example XML (Application Config)

<application>
  <name>MyService</name>
  <version>2.1.0</version>
  <debug>false</debug>
  <database>
    <host>localhost</host>
    <port>5432</port>
    <name>mydb</name>
    <pool>
      <min>5</min>
      <max>20</max>
      <timeout>30000</timeout>
    </pool>
  </database>
  <logging>
    <level>info</level>
    <file>/var/log/app.log</file>
    <rotate>true</rotate>
  </logging>
  <cors>
    <origin>https://example.com</origin>
    <origin>https://api.example.com</origin>
    <methods>GET</methods>
    <methods>POST</methods>
    <methods>PUT</methods>
  </cors>
</application>

What the Schema Reveals

The generated schema captures several important aspects:

  • Typed values: port is integer, debug is boolean, name is string
  • Nested objects: database.pool is a nested object within database
  • Arrays: cors.origin and cors.methods are detected as arrays because they have multiple occurrences
  • Structure hierarchy: The full nesting path is preserved in the schema

Using the Schema for Validation

Once generated, you can use the JSON Schema to:

  1. Validate converted JSON config files before deployment
  2. Generate TypeScript types for type-safe config access
  3. Create documentation of the expected configuration structure
  4. Build form-based config editors with schema-driven validation

Handling Optional Sections

If your sample config includes all sections, they will all appear in the schema. For optional sections that are not present in the sample, you would need to add them manually to the schema or provide a more complete sample. Enable required field detection to mark the fields that appear consistently.

Use Case

When migrating application configuration from XML to JSON format (e.g., Spring XML to JSON config, or legacy XML config to modern YAML/JSON). Generating a schema from existing XML ensures the new format preserves all the structural requirements of the original.

Try It — XML to JSON Schema

Open full tool