xml_parse
Parse an XML string into a JSON object.
Parameters
- inputstringone of
inputorsource_key - XML string; supports
${ctx.key}interpolation. - source_keystringone of
inputorsource_key - Context key containing the XML string.
- output_keystringdefault "xml_data"
- Context key for the parsed JSON output.
Providing both
inputandsource_keyis an error.
Context Output
<output_key>(defaultxml_data) — the parsed JSON object.
XML to JSON Mapping
- Elements become JSON objects keyed by tag name.
- Attributes are prefixed with
@(e.g.,@id,@lang). - Text content uses
#textwhen mixed with attributes or child elements. - Simple text-only elements are simplified to string values.
- Repeated sibling elements with the same tag become JSON arrays.
Example
local flow = Flow.new("parse_xml")
flow:step("parse", nodes.xml_parse({
input = "<book><title>Rust Programming</title><year>2024</year></book>",
output_key = "book"
}))
flow:step("done", nodes.log({
message = "Book title: ${ctx.book}"
})):depends_on("parse")
return flow