If you're working with APIs in n8n, you're probably using the HTTP Request node to connect with external services. One key aspect of this process is correctly mapping JSON fields—especially when you're sending or receiving structured data. Whether you're building workflows that integrate with CRMs, AI tools, or custom APIs, understanding how to map JSON fields in the n8n HTTP Request node can help you automate smarter and avoid frustrating errors.
In this guide, we’ll break down how to extract, format, and send JSON data properly inside n8n using the HTTP Request node, even if you’re not a developer.
Understanding JSON Field Mapping in n8n
What does it mean to "map" JSON fields?
Mapping JSON fields means taking fields from your previous nodes (or static values) and correctly transforming them into a JSON structure that the HTTP Request node can send or receive. This often involves working with Expressions, dot notation, and understanding the structure of both the input and output.
When connecting to APIs, you usually need to:
- Send JSON data in a specific format
- Handle nested objects or arrays
- Read and extract data from the JSON response
Let’s walk through how to handle both the sending and receiving of JSON fields in n8n.
Basic Setup: Using the HTTP Request Node
Before mapping any fields, add your HTTP Request node to the workflow and configure the method (GET, POST, PUT, etc.) and the URL of the API.
Example Use Case
Imagine you’re posting user data (name, email, and preferences) to a third-party API like a mailing list provider.
The API expects this JSON body:
{
"user": {
"name": "John Doe",
"email": "john@example.com",
"preferences": {
"newsletter": true,
"alerts": false
}
}
}
Let’s look at how to construct this in n8n.
Step-by-Step: How to Map JSON Fields in n8n HTTP Request
Step 1: Collect Input Data
Use a Set node or data from a previous trigger (like Webhook or Google Sheets) to define your input. For example:
{
"name": "John Doe",
"email": "john@example.com",
"newsletter": true,
"alerts": false
}
Step 2: Open the HTTP Request Node Settings
- Set the HTTP Method to
POST - Choose JSON/RAW Parameters under "Body Content Type"
- Under Body Parameters, leave it empty and enable "JSON"
Now you can use the Raw JSON/Expression editor.
Step 3: Map the JSON using Expression Mode
Click the toggle to enable expressions (fx symbol), and paste the following:
{
"user": {
"name": {{$json["name"]}},
"email": {{$json["email"]}},
"preferences": {
"newsletter": {{$json["newsletter"]}},
"alerts": {{$json["alerts"]}}
}
}
}
This expression pulls values directly from the previous node using the $json variable.
Step 4: Check the Headers
APIs often expect specific headers. You likely need:
Content-Type:application/json- Authorization headers if required
You can configure this in the Headers tab. Need help? Here’s a guide to using header authentication in n8n.
Handling Nested JSON Fields
APIs will frequently use nested objects or arrays. n8n makes it relatively straightforward to map these using dot notation and loops.
Example: Sending Multiple Products
Say you need to send this payload:
{
"orderId": "ORD-12345",
"products": [
{ "id": "P1", "quantity": 2 },
{ "id": "P2", "quantity": 1 }
]
}
Assuming your previous node outputs an array of products, you can use a Function node to reformat the JSON like this:
return [
{
json: {
orderId: "ORD-12345",
products: items.map(item => ({
id: item.json["productId"],
quantity: item.json["qty"]
}))
}
}
];
This intermediate Function node structures your payload correctly, which you can then send via HTTP.
Working with JSON Responses
Once your request is sent, you’ll often want to map fields from the JSON response.
Step-by-Step
- After the HTTP Request node, add a Set or Function node.
- Use the expression editor to access fields from the response, for example:
{{$json["data"]["user"]["id"]}}
You can also pass the entire response to Google Sheets or Notion using connected nodes. Check out the n8n-Notion integration guide for a real-world example.
Tips for Working with JSON Mapping in n8n
Here are some quick tips to help you avoid common mistakes:
- Use the Expression Editor: Always toggle into Expression mode (
fx) when writing JSON with dynamic fields. - Check JSON with JSONLint: If your workflow fails, validate your JSON body format.
- Preview Data: Use the "Execute Node" button to inspect actual input/output at each step.
- Use Dot Notation: Access nested fields as
field1.field2.subfield. - Arrays in JSON: Carefully format data using Function nodes when looping through items.
Simple Table: JSON Mapping Tools in n8n
Here’s a quick comparison of different nodes you’ll often use in combination with the HTTP Request node:
| Node | Use Case |
|---|---|
| Set | Create or rename fields before mapping |
| Function | Create complex nested or array structures |
| HTTP Request | Send/receive JSON via APIs |
| Item Lists | Format arrays, split/join items |
Real-World Workflow Example
Let’s say you're creating a workflow to collect form data via a webhook and post it to a custom CRM API.
- Webhook: Collects JSON from a form
- Set: Extracts name, email, preferences
- HTTP Request: Posts the structured user data to
https://crm.example.com/api/users - IF Node: Checks whether the response was 200 OK
- Slack Node: Sends a notification on success
By following the steps above, you’d format the request body in the HTTP node using expressions, handle nested preferences, and process responses cleanly.
To explore more creative automation ideas like this, see our top 12 n8n automation ideas.
FAQ
What is the best way to pass nested JSON in n8n?
Use the expression editor in raw JSON mode of the HTTP Request node and structure your object manually. For more complex setups, use a Function node to create nested structures.
How do I debug if my JSON mapping is failing?
Check the execution output for error messages, validate your JSON formatting, and make sure all required fields from previous nodes are present. Tools like JSONLint can help.
Can I map arrays in the HTTP Request node?
Yes. If you're sending an array (like items or products), use a Function or Item Lists node to build the array and then include it in your JSON payload.
What happens if a value in my mapping is undefined?
If the value from a previous node is missing, n8n will insert null (or cause an error based on the API behavior). Use conditional logic in expressions to set defaults if needed.
Do I need to set headers manually in the HTTP Request node?
For most external APIs, yes. Always set Content-Type: application/json, and include authorization headers as required. You can read more in the bearer token setup guide.
Copy-paste templates.
Beginner friendly.