Maps and profiles handle most JSON work in Boomi. Scripting earns its place when the structure is dynamic, when you need to reshape arrays, or when a map would become unreadable. Groovy’s built-in JsonSlurper and JsonOutput make this short work.
JSON has become the default language of modern APIs, which means it is everywhere in integration work: Shopify orders, HubSpot deals, NetSuite REST responses and SuiteQL results, webhooks from DocuSign, payloads for internal web apps. Most of it maps cleanly. But every so often you meet JSON that profiles struggle with — keys that change from record to record, arrays nested three levels deep that need flattening, or a batch API that wants five hundred documents combined into one request. That is where a ten-line Groovy script beats a map with forty functions.
This guide gives you the pattern, a set of copy-paste recipes, and — just as important — the judgement for when not to script.

Note: Boomi recommends standard shapes first and scripting as a last resort, because maps are easier for the next developer to understand. Use the scripts below when shapes genuinely cannot do the job.
When a script is the right tool
A rough guide from projects I have worked on:
| Situation | Map | Script |
|---|---|---|
| Fixed structure, field-to-field mapping | ✅ | |
| Formatting dates, defaults, simple lookups | ✅ | |
| Splitting a top-level array into documents | ✅ (profile + split) | ✅ if the array is deeply nested |
Keys that are data (e.g. {"SKU-1": 3, "SKU-2": 5}) | ✅ | |
| Filtering, grouping or summing array items | possible but messy | ✅ |
| Building a batch request from many documents | ✅ | |
| Logging a payload for debugging | ✅ |
If a map would need more than a couple of scripted functions or a chain of nested loops, the script is usually the clearer option — as long as it is short, commented and does one thing.
The pattern
import java.util.Properties
import java.io.InputStream
import groovy.json.JsonSlurper
import groovy.json.JsonOutput
for (int i = 0; i < dataContext.getDataCount(); i++) {
InputStream is = dataContext.getStream(i)
Properties props = dataContext.getProperties(i)
def json = new JsonSlurper().parse(is, "UTF-8") // Map or List
// ... change json ...
String out = JsonOutput.toJson(json)
dataContext.storeStream(new ByteArrayInputStream(out.getBytes("UTF-8")), props)
}
JsonSlurper turns JSON objects into Groovy maps and arrays into lists, so the rest is ordinary Groovy.
Every script in this guide is a variation of this loop. The essentials:
- Loop over every document. A Data Process shape receives all documents at once;
getDataCount()tells you how many. - Keep the properties.
propscarries the document’s dynamic document properties (file name, record IDs). Pass it tostoreStreamso they survive. - Store every document you want to keep. Anything you don’t store disappears from the process — useful for filtering, a nasty surprise otherwise.
How properties work in scripts is covered in detail in DPP and DDP in Groovy.
1. Add, rename and remove fields
json.source = "boomi" // add
json.customerName = json.remove("name") // rename
json.remove("internalNotes") // remove
json.total = (json.lines ?: []).sum { it.qty * it.price } ?: 0
The last line shows a handy Groovy idiom: ?: (the “Elvis” operator) supplies a default when the left side is null or empty, so a document with no lines gets a total of 0 instead of an error.
2. Filter an array
Keep only active items:
json.items = json.items.findAll { it.status == "active" }
findAll returns a new list with the items for which the closure is true. Its siblings are just as useful: find (first match), collect (transform each item), any / every (true/false tests) and groupBy.
3. Split one array into many documents
Turn {"orders": [ ... ]} into one Boomi document per order, so each can be mapped and sent individually:
for (int i = 0; i < dataContext.getDataCount(); i++) {
Properties props = dataContext.getProperties(i)
def json = new JsonSlurper().parse(dataContext.getStream(i), "UTF-8")
json.orders.each { order ->
Properties p = new Properties()
p.putAll(props) // keep the original properties
p.setProperty("document.dynamic.userdefined.DDP_ORDER_ID", order.id.toString())
String out = JsonOutput.toJson(order)
dataContext.storeStream(new ByteArrayInputStream(out.getBytes("UTF-8")), p)
}
}
Each new document gets its own dynamic document property, which later shapes can use (see dynamic process and document properties).
Splitting is the most common reason to script JSON in Boomi. Once each order is its own document, every later shape — map, decision, connector — handles one order at a time, errors are reported per order, and one bad order doesn’t fail the batch. That is exactly the shape you want for order flows such as Shopify to NetSuite.
4. Merge many documents into one array
The reverse: combine every incoming document into a single JSON array, for example for an API that accepts batches:
def all = []
Properties first = null
for (int i = 0; i < dataContext.getDataCount(); i++) {
if (first == null) first = dataContext.getProperties(i)
all << new JsonSlurper().parse(dataContext.getStream(i), "UTF-8")
}
String out = JsonOutput.toJson([records: all])
dataContext.storeStream(new ByteArrayInputStream(out.getBytes("UTF-8")), first ?: new Properties())
Batch APIs have limits — 100 or 1,000 records per request is common. If you might exceed it, merge in chunks:
import groovy.json.JsonSlurper
import groovy.json.JsonOutput
int BATCH = 100
def chunk = []
Properties first = null
def flush = {
if (chunk) {
String out = JsonOutput.toJson([records: chunk])
dataContext.storeStream(new ByteArrayInputStream(out.getBytes("UTF-8")), first ?: new Properties())
chunk = []
}
}
for (int i = 0; i < dataContext.getDataCount(); i++) {
if (first == null) first = dataContext.getProperties(i)
chunk << new JsonSlurper().parse(dataContext.getStream(i), "UTF-8")
if (chunk.size() == BATCH) flush()
}
flush()
Each output document is one request of up to 100 records.
5. Reshape: keys as data, nesting and flattening
Some APIs use object keys as values — for example stock levels keyed by SKU. Turning that into a list that a profile can describe is a one-liner:
// {"stock": {"SKU-1": 3, "SKU-2": 5}} -> {"stock": [{"sku":"SKU-1","qty":3}, ...]}
json.stock = json.stock.collect { sku, qty -> [sku: sku, qty: qty] }
And flattening a nested structure into simple rows (handy before writing a CSV or a database table):
// one row per order line, with order fields repeated
def rows = json.orders.collectMany { o ->
(o.lines ?: []).collect { l -> [orderId: o.id, customer: o.customer?.name, sku: l.sku, qty: l.qty] }
}
6. Pretty-print for logs and debugging
String pretty = JsonOutput.prettyPrint(JsonOutput.toJson(json))
Use compact output for real requests and pretty output only for logging.
Combine it with the process logger to see exactly what a document looked like at a given point — invaluable when an API rejects a payload and you need to know what was sent:
import com.boomi.execution.ExecutionUtil
def logger = ExecutionUtil.getBaseLogger()
logger.info("Payload sent:\n" + JsonOutput.prettyPrint(JsonOutput.toJson(json)))
Watch out: Logs are visible to anyone with access to Process Reporting. Don’t log payloads that contain personal data, payment details or secrets in production — log IDs and counts instead.
Gotchas
- Character encoding: always pass
"UTF-8"when parsing and when converting back to bytes. - Numbers: decimals are parsed as
BigDecimal, which is exact, so money values stay exact. Convert toStringexplicitly when writing to properties. - Missing keys return
null; use the safe-navigation operator (json.customer?.address?.city) to avoid errors. - Groovy version: check which Groovy version your Data Process shape uses. Newer helpers such as
JsonGenerator(Groovy 2.5+) may not be available. - Large payloads:
JsonSlurperloads the whole document into memory. For very large files, split earlier (for example by reading the file in chunks) rather than parsing hundreds of megabytes in one go. - Order of keys: JSON objects are unordered; don’t write code (or tests) that depends on key order.
Test scripts before they reach Boomi
Iterating on a script inside a Data Process shape is slow: edit, save, run a test, open the document. A faster loop is to run the same script on your machine against sample files, with small stand-ins for Boomi’s dataContext and ExecutionUtil. The full setup is in Set up VS Code to run and test Boomi Groovy scripts locally — the example there splits an orders file exactly like recipe 3 above.
Further reading
Need help with an integration?
Scripts are a small part of good integration design, but they are often where maintainability is won or lost. If you would like a review of existing scripts, or help with an integration that has outgrown its maps, see the Boomi integration consultant page or get in touch.

Comments 0
No comments yet. Start the discussion.