Clean, Flatten and Rename JSON Between Make Modules (One Code Step)
Updated October 2026
To clean, flatten or rename JSON between two Make modules, put one code step between them: map the collection in as input, reshape it in ten to thirty lines of JavaScript, and return the result so the next module sees clean fields in its mapping panel. The seven snippets below cover the reshaping jobs that make up about 40% of the inline scripts people run through the CustomJS Execute Inline JavaScript module: renaming keys with a mapping object, flattening nested collections to dot keys and back, dropping nulls and empty strings, coercing strings to numbers, booleans and ISO dates, picking or omitting fields, normalizing key names to snake_case or camelCase, and repairing almost-JSON from an AI module.
Each snippet shows its input and output, and the last section combines them into one cleanup pipeline you can paste and edit.
TL;DR
Rename keys with a plain mapping object: out[rename[key] ?? key] = value. One line, any number of fields.
Flatten nested collections to dot keys (customer.address.city) with a 7-line recursive function, and unflatten with the reverse.
Drop null and "" at every depth with one recursive compact(), instead of one ifempty() per field.
Coerce "1.234,56" to 1234.56, "true" to true and 31.10.2026 to 2026-10-31 in the same pass. Keep zip codes and IDs on a text list so they stay strings.
The full pipeline is about 30 lines, runs in about 121 ms (median across inline scripts), and costs 1 Make credit per call.
Make's own map(), get(), pick(), omit() and the JSON app are enough when you reshape one or two fields of a known structure. The last section says when.
How do I get a Make collection into the code step and back out?
Two mechanics, then every snippet below reads the same way. Whatever you map into the module's Input field arrives in the code as the input variable. A single mapped value arrives as a string, a valid JSON string is parsed into an object or array. A Make collection is not a JSON string, so either put Make's Transform to JSON module (JSON app) in front of the code step, or type a small JSON object into the Input field with the mapped pills inside the quotes. The first line of every snippet handles both cases: typeof input === "string" ? JSON.parse(input) : input.
On the way out, the code must end with return. Set Return Type to Object (or Array) and Make lists every returned field in the mapping panel of the following modules, exactly as if a Parse JSON module had produced them.
How do I rename keys in Make with a mapping object?
A form, a CRM export or a Sheets row gives you keys like First Name and E-Mail, and the API you are posting to wants first_name and email. In Make's mapping panel that is one hand-typed field per key in a Create JSON module. In code it is a lookup table.
Keys that are not in the mapping pass through unchanged, which is what ?? key does.
How do I flatten a nested collection to dot keys, and unflatten it again?
Spreadsheets, CSV exports and most form tools want one flat row. Webhooks and APIs send nested collections. Flattening turns customer.address.city into a single top-level key with that exact name, so a Google Sheets "Add a row" module can map it in one click. The reverse builds the nesting back when an API expects it.
Arrays are left intact on purpose (the tags array stays an array). If you want tags.0, tags.1 keys instead, remove the !Array.isArray(v) check. The reverse:
const unflatten = (flat)=>{const out = {};
for(const[path, v]ofObject.entries(flat)){const keys = path.split(".");
let cur = out;
keys.slice(0, -1).forEach((k)=>(cur = cur[k] ??= {}));
cur[keys.at(-1)] = v;
}return out;
};
returnunflatten(data); // data = the flat object from the step before
Feeding the flat output to unflatten returns the original nested input unchanged.
How do I remove null values and empty strings from JSON in Make?
Many APIs treat "phone": "" as "overwrite the phone with nothing" and "fax": null as a validation error. Make's ifempty() fixes one field at a time and cannot remove the key itself. This recursive compact() deletes empty values at every depth, inside arrays included.
The number 0 and the boolean false survive, because the test is v === null || v === "" and not a truthiness check. Add || v === undefined or a whitespace trim if your source needs it.
How do I convert strings to numbers, booleans and ISO dates in one pass?
Webhooks and spreadsheets send everything as text: "1.234,56", "3", "true", "31.10.2026". Make's parseNumber(number; decimal separator) handles one value when you already know the separator, and parseDate() handles one value when you know the format. A coerce() function applied to every field does all three decisions per value.
The comma-decimal regex requires digit groups of three before the comma, so "1.234,56" matches and a US-style "1,234.56" falls through untouched. If your amounts mix both conventions or carry currency symbols, the no-code Parse Localized Number module detects the format per value, including accounting negatives like (500). The date rule only converts the unambiguous DD.MM.YYYY shape; full timezone handling is a separate topic and deserves its own article.
Use our Make App to execute JavaScript directly in Make.
How do I pick or omit fields before sending data to an API?
A record from your database has 40 fields, the API accepts 5, and two of the others (a password hash, an internal score) must never leave the scenario. Make has pick(collection; key1; ...) and omit(collection; key1; ...) for exactly this (checked on help.make.com, October 2026), and if the field list is short and fixed, use them. In code the same helpers take a list, which matters when it is long or comes from a variable.
Prefer pick when sending data out: a new field added upstream cannot leak by accident. Prefer omit when storing data: new fields are kept until you decide otherwise.
How do I normalize all keys to snake_case or camelCase?
When three sources deliver Order ID, orderId and order_id, a rename table grows without end. Normalizing every key at every depth is one regex applied recursively, and the rest of the scenario maps against one spelling.
Return renameKeys(data, toCamel) instead and the same input becomes orderId, lineItems, unitPrice, customerAddress and zipCode. toCamel goes through snake_case first so that lineItems keeps its capital I instead of collapsing to lineitems. All-caps acronyms like SKU become sku in both styles.
How do I repair AI JSON with code fences and trailing commas?
You ask ChatGPT or Claude for "JSON only" and get a markdown fence, a sentence of prose, a Python True and a trailing comma. Make's Parse JSON module throws on all four. The repair is four string operations before JSON.parse.
Input (the raw AI message, mapped as text)
Sure! Here is the extracted data:
```json
{"name":"Acme Corp",
"active": True,
"tags":["b2b", "enterprise",],
}
```
Let me know if you need anything else.
Code
const raw = typeofinput === "string" ? input : input.text;
let text = raw.replace(/```(?:json)?/gi, ""); // 1. code fencesconst start = Math.min(
...[text.indexOf("{"), text.indexOf("[")].filter((i)=> i !== -1));
const end = Math.max(text.lastIndexOf("}"), text.lastIndexOf("]"));
text = text.slice(start, end + 1)// 2. surrounding prose
.replace(/[\u201C\u201D]/g, '"')// 3. smart quotes
.replace(/\bTrue\b/g, "true")// 4. Python literals
.replace(/\bFalse\b/g, "false")
.replace(/\bNone\b/g, "null")
.replace(/,\s*([}\]])/g, "$1"); // 5. trailing commasreturnJSON.parse(text);
The literal replacements are heuristics: a string value that legitimately contains the word True would be rewritten too. If you want the same repairs without code, plus a Was Repaired flag and a list of what was fixed, the AI JSON Parser module does this as a drop-in replacement for Parse JSON after any AI module.
How do I combine all of this into one cleanup pipeline?
A webhook order arrives with mixed key casing, empty strings, a comma-decimal total and a field that must not be forwarded. The pipeline below normalizes keys to snake_case, renames two, drops one, removes empty values and coerces types in a single recursive pass. Edit the three constants at the top and it fits most payloads.
Note what the TEXT list is for: without it, "10115" would become the number 10115 and a Hamburg zip code "01234" would lose its leading zero. Zip codes, phone numbers and order IDs are text that happens to look numeric; the first version of this pipeline got that wrong in testing. Add return flatten(clean(data)) with the flatten function from above when the destination is a spreadsheet row.
The whole pipeline runs in about 121 ms, which is the median for inline scripts on CustomJS, and 97.7% of runs finish inside a second. Make bills 1 credit for the call regardless of runtime, and the execution counts as one request against the CustomJS quota (600 per month on the free plan, 100, 500 or 5,000 per day on the paid plans). If the same cleanup is needed in several scenarios, save it once as a stored function with RENAME, DROP and TEXT as named parameters, and call it by name from each one.
When Make's built-in is enough
A code step is the wrong tool when the mapping panel does the job in one function. These cases, checked against Make's function reference on help.make.com in October 2026, do not need code:
Reading one nested value.get(collection; customer.address.city) returns the value by dot path. Flatten only when you need every nested field as a column.
Pulling one property out of an array of collections.map(lineItems; sku) returns a plain array of SKUs, with optional filtering on a second key. It supports dot notation for nested keys.
Keeping or removing a handful of known keys.pick(collection; id; email; name) and omit(collection; password_hash) do that natively.
One field with a known type.parseNumber(total; ,), toString(value), ifempty(phone; null) and parseDate(due; DD.MM.YYYY) are correct and cost nothing extra when the format never varies.
A fixed output shape. The JSON app's Parse JSON module (with a data structure Make can generate from one sample run) and Create JSON or Transform to JSON give you a typed, mappable structure without code. Renaming five known keys in Create JSON is five pills, and that is fine.
A small array you need as bundles anyway. Iterator plus Set variable or an aggregator costs one operation per item, which is fine for a dozen items, and every step is visible in the execution log.
Reach for code when the key names are not known in advance (normalizing casing, renaming by table), when a rule has to apply at every depth (dropping empties, coercing types), when the array has hundreds of items, or when you need three or more of these transformations on the same payload. The comparison in one table:
Task
Make built-in
One code step
Rename keys
Create JSON, one pill per key, keys fixed at design time
Mapping object, unknown keys pass through or are dropped
Flatten nested collection
get() per field, or flatten() for arrays of arrays only
All fields at all depths, dot-key names generated
Remove null / empty
ifempty() per field, key stays in the payload
Key removed, recursive, arrays included
Coerce types
parseNumber(), parseDate() with a known format per field
Format detected per value, keep-list for IDs and zips
Pick / omit fields
pick(), omit(), built in
Same, with the key list from a variable
snake_case / camelCase
No function for key casing
One regex, applied recursively
Repair AI JSON
Parse JSON throws on fences, prose, trailing commas
Four replacements, or the AI JSON Parser module
Operations per run
1 per module; Iterator patterns 1 per item
1 Make credit plus 1 CustomJS request
Grouping and summing an array is the other reshaping job that Make's Numeric Aggregator handles for one function at a time and without a group-by. That one has its own article: Group and sum arrays in Make.
Setup is one time: add the CustomJS app to a scenario, paste your API key as the connection, map your collection into Input and paste a snippet. The free plan is 600 requests per month and needs no credit card.
Turn a Make bundle into the exact JSON an API expects (nested arrays, computed totals, ISO timestamps, idempotency keys) in one JavaScript step, then map it into Make's HTTP module.
Call OpenAI from a Make code step with a strict JSON schema: classify 50 tickets in one operation, validate the batch, retry 429s with backoff, and map the result fields in the next module.
Get an app-only Microsoft Graph token with the client-credentials flow and send a 20-request $batch from one Make code step. Input, output, limits and when Make's own modules are enough.