Converts an XML message body to JSON using a structural, heuristic mapping: elements and attributes both become JSON properties, and a repeated element becomes a JSON array while the same element occurring once becomes an object.
Element order, mixed content, and namespaces are not preserved. Only messages with an XML content type are converted; other bodies pass through unchanged.
Malformed XML aborts the exchange with a Problem Details response (400 in the request flow, 500 in the response flow).
The character encoding is taken from the Content-Type header if present, otherwise read from the XML prolog, and the result is always UTF-8 encoded JSON.
For contract-driven integrations that need a fixed output shape, a template, XSLT, or schema-aware mapping gives more control. See tutorials/xml/20-XML-to-JSON.yaml.
xml2Json:
[ keepString: true | false ] # default: false
[ convertNilAttributeToNull: true | false ] # default: true
forceList: # 0..*; always render these element names as arrays
- <element-name>
...
Example Configuration
api:
port: 2000
flow:
- xml2Json: {}
api:
port: 2000
flow:
- xml2Json: {}
Syntax
xml2Json:
convertNilAttributeToNull: <boolean>
forceList:
- <string>
keepString: <boolean>
xml2Json:
convertNilAttributeToNull: <boolean>
forceList:
- <string>
keepString: <boolean>
Attributes
| Name | Required | Default | Description | Examples |
|---|---|---|---|---|
| convertNilAttributeToNull | false | true | If true, converts elements marked xsi:nil="true" into JSON null values. | false |
| forceList | false | - | - | - |
| keepString | false | false | If true, keeps every element's text as a JSON string instead of coercing numeric- or boolean-looking text into JSON numbers and booleans. | true |