webdev_xml_to_json
Convert XML documents into JSON objects, preserving nesting, attributes, text nodes, and repeated elements. Supports numeric and boolean coercion, attribute prefix, and namespace stripping.
Instructions
XML to JSON Converter. Convert an XML document into a JSON object, preserving element nesting, attributes (with a configurable prefix), text nodes, and repeated siblings (collapsed into arrays), with optional numeric and boolean type coercion and namespace stripping. Parsing is a local regex tokenizer that never resolves or fetches external entities or DTDs, so it is XXE-safe and fully offline. Use format_json afterward to re-pretty-print or minify the result, webdev_json_to_csv to flatten JSON into CSV, or webdev_xml_formatter to tidy XML without converting it. Read-only, non-destructive, contacts no external service, rate-limited to 30 requests per minute for anonymous callers. Returns the JSON string plus the parsed data object, an isValid flag, errors, and element/attribute statistics.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| xml | Yes | The XML document to convert. Must be non-blank and have a single root element. Mismatched or unclosed tags produce an isValid false result with an error message. | |
| prettyPrint | No | Indent the JSON output with two spaces when true; emit compact single-line JSON when false. | |
| preserveAttributes | No | Include element attributes in the output (each key prefixed by attributePrefix) when true; drop all attributes when false. | |
| attributePrefix | No | Prefix prepended to attribute names so they do not collide with child element keys. | @ |
| textNodeName | No | Key used to hold an element text value when that element also has attributes or child elements. | _text |
| removeEmptyNodes | No | Omit elements whose converted value is empty (empty string, empty object, or null) when true. | |
| numericConversion | No | Coerce numeric-looking text values into JSON numbers when true; keep them as strings when false. | |
| booleanConversion | No | Coerce the literal text true and false into JSON booleans when true; keep them as strings when false. | |
| ignoreNamespaces | No | Strip namespace prefixes from element and attribute names (for example soap:Body becomes Body) when true. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| original | No | The submitted XML, echoed back. | |
| json | No | The JSON output as a string (indented or compact per prettyPrint). | |
| data | No | The parsed JSON value as a structured object (null when parsing failed). | |
| isValid | No | True when the XML parsed successfully and JSON was produced. | |
| errors | No | Parse or validation error messages (empty when isValid is true). | |
| warnings | No | Non-fatal warning messages. | |
| stats | No | Counts and metrics describing the converted document. |