Skip to main content

json_to_xml

Convert a JSON string to XML, wrapped in a configurable root element.

Parameters​

ParameterTypeRequiredDescription
inputstringYesJSON string to convert.
root_elementstringNoName of the XML root element to wrap the output in (default: root).

Response​

FieldTypeDescription
outputstringThe converted XML string.

Example​

{
"input": "{\"name\": \"Alice\", \"age\": 30}",
"root_element": "person"
}

Result:

{
"output": "<person>\n <name>Alice</name>\n <age>30</age>\n</person>"
}

Errors​

Each failure carries a precise code in the response. Argument-schema and server errors are JSON-RPC protocol errors; a rejected value is returned as a tool result with isError: true (so the agent can read the code and self-correct).

CodeWhenDelivered as
invalid_argumentsinput is missing or not a string, or root_element is not a string.protocol error (invalid_params)
invalid_jsonThe input string is not valid JSON.tool error (isError)
internal_errorAn unexpected server error.protocol error (internal_error)

Mapping Convention​

JSONXML
Object key "foo"<foo> child element
Object key "@id"Attribute id="..." on the parent element
Object key "$text"Text content of the parent element
Array ["a", "b"]Repeated sibling <foo>a</foo><foo>b</foo> elements
nullSelf-closing element <foo/>
String, number, boolElement text content

Notes​

  • Round-trips between json_to_xml and xml_to_json are not guaranteed to be lossless. In particular, numbers are serialized as text and parsed back as strings.
  • XML special characters (<, >, &, ", ') in values are automatically escaped.