xtract.bot
POST /api/xml-to-json

Parse XML to JSON. Attributes prefixed with `@_`, configurable type-coercion for numeric/boolean leaves, whitespace-trimming.

Parses XML into JSON. Attributes appear under keys prefixed with `@_` (so `<a href="x"/>` becomes `{ a: { "@_href": "x" } }`); text content under elements with both attributes and children lives at `#text`. Options: - `parseValues` (default false): coerce numeric and boolean leaves to typed JS values (`<n>42</n>` → `42` instead of `"42"`). No DTD validation is performed.

Inputs

NameTypeDefaultDescription
xml*stringXML source.
preserveAttributesbooleantrueInclude attributes (prefixed `@_`) in output.
parseValuesbooleanfalseCoerce numeric/boolean leaves to typed JS values.
trimValuesbooleantrueTrim whitespace from text nodes.

Response

Modes: json. Cache: yes (24h TTL).

Code samples

Built from the simple example.


curl -X POST https://api.xtract.bot/api/xml-to-json \
  -H "Content-Type: application/json" \
  -H "Accept: application/json" \
  -H "X-Account-Id: $XTRACT_ACCOUNT_ID" \
  -H "X-Api-Key: $XTRACT_API_KEY" \
  -d '{
  "xml": "<?xml version=\"1.0\"?><note priority=\"high\"><to>Tove</to><from>Jani</from><body>Don't forget!</body></note>"
}'