⚒️ 🛠️ Transform JSON to XML for Enhanced AI Prompt Formatting

2,204 views · ⚒️ Engineering

Description

Overview

This template provides a powerful and configurable utility to convert JSON data into a clean, well-structured XML format. It is designed for developers, data analysts, and n8n users who need to interface with legacy systems, generate structured reports, or prepare data for consumption by Large Language Models (LLMs), which often exhibit improved understanding and parsing with XML-formatted input.

Use Cases

This workflow is ideal for solving several common data transformation problems:

How it works

This workflow acts as a powerful, configurable JSON to XML converter. It takes a JSON object as input and performs the following steps:

  1. Recursively Parses JSON: It intelligently navigates through the entire JSON structure, including nested objects and arrays.
  2. Handles Data Types:
    • Primitive Arrays (e.g., ["a", "b", "c"]) are joined into a single string with a safe delimiter.
    • Complex Arrays (of objects) are converted into indexed XML tags (<0>, <1>, etc.).
    • Dates are automatically detected and formatted into a readable YYYY-MM-DD HH:mm:ss format.
  3. Generates XML String: It constructs a final XML string based on the logic and configuration set inside the Code node. The output is provided in a single xml field, ready for use.

Set up steps

Setup time: ~1 minute

This workflow is designed to be used as a sub-workflow (or “child workflow”).

  1. In your main workflow, add an Execute Workflow node.
  2. In the Workflow parameter of that node, select this “JSON to XML Converter” workflow.
  3. That’s it! You can now send JSON data to the Execute Workflow node and it will return the converted XML string in the xml field.

Customization Options

The true power of this template lies in its customizability, all managed within the configuration section at the top of the Code node. This allows you to fine-tune the output XML to your exact needs.

Prerequisites

🔗 Nodes Used

Execute Workflow Trigger

📥 Import

Download workflow.json and import into n8n: Workflow menu → Import from File

📖 Importing guide · 🔑 Credential setup