Blog
Wild & Free Tools

JSON to XML in SAP CPI — Browser-Based Prototype and Production Policy

Last updated: April 2026 7 min read
Quick Answer

Table of Contents

  1. CPI's built-in JSON-to-XML shape
  2. The prototyping workflow
  3. Arrays and the "single element" problem
  4. Groovy script as escape hatch
  5. Namespace mapping — the one that bites
  6. Frequently Asked Questions

SAP Cloud Integration (CPI) has a built-in JSON-to-XML converter shape that handles namespace mapping, array wrapping, and attribute promotion via config. For production flows, use it. For design-time prototyping — seeing the target XML shape before wiring an Integration Flow — a browser converter gives you the element layout in seconds. This guide walks through the combined workflow.

CPI's Built-In JSON-to-XML Shape

In the CPI Integration Flow designer, the JSON to XML Converter step has these knobs:

These are production features. A browser tool doesn't replicate them — it does the base element-level conversion so you can preview the shape before tuning CPI's config knobs.

The Prototyping Workflow

  1. Grab a sample JSON payload your source system sends.
  2. Paste into our browser converter, set root to match your target element name.
  3. Copy the XML output.
  4. Compare with your target schema (the WSDL/XSD your receiver expects).
  5. Identify the gaps: namespaces needed? attributes vs elements? specific wrapping?
  6. Now wire the CPI JSON-to-XML Converter with config that fills those gaps.

Without the preview, you'd iterate in CPI itself — trigger, inspect, adjust, re-trigger. Each cycle is seconds to minutes depending on your tenant. The browser preview cuts the design loop to zero.

Sell Custom Apparel — We Handle Printing & Free Shipping

Arrays and the "Single Element" Problem

CPI's converter, like ours, produces repeating siblings for JSON arrays. A JSON array of one item looks identical to a single object — which often breaks receivers expecting a wrapping element.

Workarounds in CPI:

Know the issue exists before you deploy. A browser preview with a one-item array exposes it immediately.

Groovy Script as Escape Hatch

When CPI's config-based converter can't match the target schema, a Groovy script step does custom conversion. Skeleton:

import com.sap.gateway.ip.core.customdev.util.Message
import groovy.json.JsonSlurper
import groovy.xml.MarkupBuilder

Message processData(Message message) {
  def json = new JsonSlurper().parse(message.body)
  def writer = new StringWriter()
  def xml = new MarkupBuilder(writer)
  // Build XML here based on json structure
  message.setBody(writer.toString())
  return message
}

This is your fallback when CPI's declarative converter hits its limits — complex attribute rules, mixed content, conditional wrapping. For simple format flips, stick with the converter shape.

Namespace Mapping — The One That Bites

Most SAP receivers require namespaced XML (ns1:Customer, ns1:Id). Neither our browser tool nor the raw CPI output produces namespaces automatically — you configure CPI's Namespace Mapping to add them based on JSON key prefixes.

Prototyping approach:

  1. Browser tool: paste JSON, see plain (un-namespaced) XML shape.
  2. CPI Namespace Mapping: add ns1 prefix mapped to the target namespace URI.
  3. Result: same shape, plus xmlns:ns1="..." declarations.

Knowing the shape first means the CPI mapping config has no surprises.

Preview Your CPI Output Before You Build

Paste sample JSON, see the element shape, then configure CPI with no surprises.

Open Free JSON to XML Converter

Frequently Asked Questions

Does SAP CPI's JSON-to-XML converter add namespaces automatically?

Only if configured. The Namespace Mapping section of the converter step lets you map JSON property prefixes to XML namespace URIs. Without config, output has no namespaces — same as our browser tool.

Can I use this browser tool inside a CPI iFlow?

No — it's for design-time prototyping only. CPI doesn't call external URLs for conversions. Use CPI's built-in converter shape or a Groovy script for runtime.

What about SAP PI / PO (on-prem)?

PI/PO has a JSON to XML converter module too (SAP Note 2310812). Same principle — use the built-in module for production, our browser tool for prototyping.

How do I handle a JSON array with one element mapping to a single XML element?

CPI has a "force array" setting in the converter, or use a Content Modifier upstream to wrap single items. Browser preview exposes the issue so you know to configure it.

Andrew Walsh
Andrew Walsh Developer Tools & API Writer

Andrew worked as a developer advocate at two SaaS startups writing API documentation used by thousands of engineers.

More articles by Andrew →
Launch Your Own Clothing Brand — No Inventory, No Risk