n8n JSON: Parse, Transform & Manipulate Data in 2026
If you're building workflows in n8n, you'll inevitably work with JSON data. Whether you're receiving webhook payloads, calling APIs, or integrating multiple tools, understanding how to parse, transform, and manipulate JSON is critical for building reliable automations.
This guide walks through practical n8n JSON techniques with real examples you can use today on n8nautomation.cloud.
Why JSON Matters in n8n Workflows
JSON (JavaScript Object Notation) is the standard data format for modern APIs and webhooks. In n8n, nearly every node outputs data as JSON objects, and most integrations expect JSON input.
Common scenarios where you'll manipulate JSON in n8n include:
- Parsing webhook payloads from Stripe, Shopify, or custom applications
- Extracting specific fields from API responses (like pulling email addresses from HubSpot contacts)
- Restructuring data to match the format required by downstream nodes
- Merging data from multiple sources into a single JSON object
- Converting JSON strings into usable objects for processing
Mastering JSON manipulation means you can connect any tool to any workflow, regardless of format differences.
Parsing JSON Strings
Sometimes you'll receive JSON data as a plain text string—common with certain webhooks or database fields. Before you can work with this data, you need to parse it into a proper JSON object.
Using the Code Node to Parse JSON
The most reliable way to parse JSON strings in n8n is with the Code node:
- Add a Code node to your workflow after receiving the JSON string.
- Select Run Once for All Items mode.
- Use this code to parse the JSON string:
// Get the JSON string from previous node const jsonString = $input.first().json.jsonField; // Parse it into an object const parsedData = JSON.parse(jsonString); // Return the parsed data return [{ json: parsedData }]; - Reference
jsonFieldwith the actual field name from your data.
This approach handles complex nested JSON strings and provides clear error messages if parsing fails.
Alternative: Using Expressions
For simpler cases, you can parse JSON directly in a Set node using n8n's expression syntax:
- Add a Set node.
- Click Add Value and select String.
- In the expression field, use:
{{ JSON.parse($json.yourStringField) }}
Tip: Always test JSON parsing with sample data first. Invalid JSON (missing quotes, trailing commas) will break your workflow, so validate your data source before deployment.
Extracting Nested Data from JSON
Real-world JSON is rarely flat. API responses often contain deeply nested objects and arrays. Here's how to extract the exact values you need.
Accessing Nested Properties
Imagine you receive this JSON from a CRM webhook:
{
"contact": {
"id": 12345,
"profile": {
"name": "Sarah Johnson",
"email": "sarah@example.com",
"company": {
"name": "Acme Corp",
"industry": "Technology"
}
}
}
}
To extract the company name in a Set node:
- Add a Set node.
- Click Add Value → String.
- Set the field name to
companyName. - Use this expression:
{{ $json.contact.profile.company.name }}
The Set node will output { "companyName": "Acme Corp" }.
Using the Code Node for Complex Extraction
When you need to extract multiple nested fields or apply conditional logic, the Code node gives you more control:
// Extract multiple nested fields
const contact = $input.first().json.contact;
return [{
json: {
contactId: contact.id,
fullName: contact.profile.name,
email: contact.profile.email,
companyName: contact.profile.company.name || 'Unknown',
industry: contact.profile.company.industry
}
}];
This code safely extracts data and provides fallback values (like 'Unknown' for missing companies).
Transforming JSON Structures
Often you'll need to reshape JSON data to match what a downstream API expects. This is one of the most common n8n JSON operations.
Flattening Nested Objects
Some tools don't accept nested JSON. Here's how to flatten complex structures:
const input = $input.first().json;
return [{
json: {
contact_id: input.contact.id,
contact_name: input.contact.profile.name,
contact_email: input.contact.profile.email,
company_name: input.contact.profile.company.name,
company_industry: input.contact.profile.company.industry
}
}];
This converts nested data into a flat structure suitable for CSV exports or simple database inserts.
Creating Nested Structures
Conversely, you might receive flat data that needs to be nested for an API:
const input = $input.first().json;
return [{
json: {
contact: {
id: input.contact_id,
profile: {
name: input.contact_name,
email: input.contact_email,
company: {
name: input.company_name,
industry: input.company_industry
}
}
}
}
}];
This is essential when working with GraphQL APIs or tools like Notion that require specific JSON structures.
Handling JSON Arrays
JSON arrays require special handling in n8n. You'll often need to loop through arrays, filter items, or transform each element.
Processing Each Array Item
When you receive an array of objects (like a list of orders or contacts), use the Split Out node:
- Add a Code node to output your array properly.
- Add a Split Out node and connect it.
- Set the field to split to the path of your array (e.g.,
orders).
This converts a single item with an array into multiple workflow items—one per array element. You can then process each individually.
Filtering Arrays
To extract only certain items from an array, use the Code node with JavaScript filter:
const data = $input.first().json;
const orders = data.orders;
// Filter for orders over $100
const filteredOrders = orders.filter(order => order.total > 100);
return filteredOrders.map(order => ({ json: order }));
This outputs only orders meeting your criteria as separate workflow items.
Mapping Arrays
Transform every item in an array using the map function:
const data = $input.first().json;
const customers = data.customers;
// Extract just names and emails
const simplified = customers.map(customer => ({
name: customer.fullName,
email: customer.contactEmail
}));
return [{ json: { customers: simplified } }];
This is useful for cleaning up data before sending it to another tool.
Tip: When working with large arrays (1000+ items), consider using the Split in Batches node to process data in chunks. This prevents memory issues and keeps your workflow responsive on n8nautomation.cloud.
Advanced JSON Operations with Code Node
For complex JSON manipulation, the Code node is your most powerful tool. Here are advanced techniques for real-world scenarios.
Merging Multiple JSON Objects
Combine data from different nodes or API calls:
// Assuming you have two items from previous nodes
const userData = $input.first().json;
const orderData = $input.all()[1].json;
// Merge them
const merged = {
...userData,
...orderData,
mergedAt: new Date().toISOString()
};
return [{ json: merged }];
This combines two JSON objects into one, with later properties overwriting earlier ones if there are conflicts.
Deep Cloning JSON Objects
Prevent accidental mutations when working with complex objects:
const original = $input.first().json;
// Create a deep clone
const cloned = JSON.parse(JSON.stringify(original));
// Modify the clone safely
cloned.status = 'processed';
cloned.processedAt = new Date().toISOString();
return [{ json: cloned }];
Conditionally Adding Fields
Add fields to JSON only when certain conditions are met:
const data = $input.first().json;
const output = {
id: data.id,
name: data.name,
email: data.email
};
// Add optional fields only if they exist
if (data.phone) {
output.phone = data.phone;
}
if (data.company && data.company.name) {
output.companyName = data.company.name;
}
return [{ json: output }];
This prevents sending null or undefined values to APIs that don't handle them well.
Stringifying JSON for API Requests
Some APIs require JSON to be sent as a string in a specific field:
const data = $input.first().json;
const payload = {
eventType: 'user.created',
data: JSON.stringify(data),
timestamp: Date.now()
};
return [{ json: payload }];
Common JSON Errors and How to Fix Them
Working with JSON in n8n can produce cryptic errors. Here's how to diagnose and fix the most common issues.
"Cannot read property of undefined"
This happens when you try to access a nested property that doesn't exist. Fix it with optional chaining:
// Instead of this (breaks if company is undefined):
const name = data.contact.company.name;
// Use optional chaining:
const name = data.contact?.company?.name || 'Unknown';
"Unexpected token in JSON"
This means your JSON string is malformed. Common causes:
- Missing quotes around property names
- Trailing commas in objects or arrays
- Single quotes instead of double quotes
- Unescaped special characters in strings
Use a JSON validator or the Code node to clean the data before parsing:
let jsonString = $input.first().json.rawData;
// Remove trailing commas (common issue)
jsonString = jsonString.replace(/,\s*}/g, '}').replace(/,\s*\]/g, ']');
const parsed = JSON.parse(jsonString);
return [{ json: parsed }];
"JSON.parse is not a function"
This occurs when you try to parse data that's already an object. Check the data type first:
const data = $input.first().json.data;
let parsed;
if (typeof data === 'string') {
parsed = JSON.parse(data);
} else {
parsed = data; // Already an object
}
return [{ json: parsed }];
"Maximum call stack size exceeded"
This happens with circular references in JSON objects. Use a safe stringify approach:
const seen = new WeakSet();
const safeStringify = (obj) => {
return JSON.stringify(obj, (key, value) => {
if (typeof value === 'object' && value !== null) {
if (seen.has(value)) {
return '[Circular]';
}
seen.add(value);
}
return value;
});
};
const result = safeStringify($input.first().json);
return [{ json: { stringified: result } }];
Start Building Better JSON Workflows Today
Mastering JSON manipulation in n8n unlocks the full potential of workflow automation. Whether you're parsing webhook data, transforming API responses, or merging multiple data sources, these techniques will help you build more reliable and flexible workflows.
The Code node is your most powerful tool for complex JSON operations, while the Set node and expressions work well for simple transformations. Combine these approaches based on your specific needs.
Ready to put these JSON techniques into practice? Deploy your workflows on n8nautomation.cloud starting at $7/month with automatic backups and 24/7 uptime—no JSON configuration files required.