JSON to XML in SAP CPI — Browser-Based Prototype and Production Policy
- SAP CPI ships a JSON-to-XML converter shape — use it in production. A browser tool preview gets you the target shape before you wire the IFlow.
- CPI's converter handles namespace mapping and array-to-repeating-element conventions via config; the browser converter shows you the element-level output.
- Groovy script is the escape hatch when CPI's config-based converter can't match your target schema.
Table of Contents
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:
- JSON Namespace Mapping — map a JSON property prefix (like
n1:) to an XML namespace. - Add XML Root Element — wrap output in a single root, matching target XSD.
- Suppress JSON Root Element — skip the outer JSON object's key as an element.
- Streaming / In-Memory — pick based on payload size.
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
- Grab a sample JSON payload your source system sends.
- Paste into our browser converter, set root to match your target element name.
- Copy the XML output.
- Compare with your target schema (the WSDL/XSD your receiver expects).
- Identify the gaps: namespaces needed? attributes vs elements? specific wrapping?
- 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 ShippingArrays 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:
- Use a Content Modifier to wrap single items in a fake array before conversion.
- Post-convert with a Message Mapping to add the wrapping element.
- Use a Groovy script (see next section) for fine-grained control.
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:
- Browser tool: paste JSON, see plain (un-namespaced) XML shape.
- CPI Namespace Mapping: add
ns1prefix mapped to the target namespace URI. - 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 ConverterFrequently 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.

