Working with JSON data in automation platforms like n8n is extremely common. Whether you're handling responses from an API or parsing webhook payloads, knowing how to extract specific values from JSON in n8n is essential. For beginners just starting out or intermediates looking to refine their workflows, mastering this skill can help you build more dynamic and powerful automation solutions.
In this guide, we’ll walk through step-by-step how to extract specific values from JSON in n8n—even if you have no previous coding experience. We’ll cover basic extraction using a Set node, explain dot notation for nested fields, and share real-world examples to solidify your understanding.
Understanding JSON in n8n
Before jumping into the practical steps, let’s clarify what JSON looks like and why it matters in n8n.
JSON (JavaScript Object Notation) is a structured format that stores data in key-value pairs. Here’s a quick example:
{
"user": {
"name": "Alice",
"email": "alice@example.com",
"roles": ["admin", "editor"]
},
"status": "active"
}
In n8n, whenever you fetch data—via an API call, a webhook, or a database—you usually receive a JSON response. The next step is telling n8n exactly which piece of that data you want to use in your workflow.
Step 1: Get the JSON Data into Your Workflow
Using an HTTP Request Node
Most commonly, you’ll pull JSON data from an external API via the HTTP Request node.
For example, suppose you send a GET request to an API endpoint and receive this response:
{
"data": {
"id": 123,
"title": "How to Automate Workflows",
"author": {
"name": "John Doe",
"email": "john@example.com"
}
}
}
After the request, the response will be accessible in the next node using expressions.
Step 2: Use a Set or Function Node to Extract Data
To extract specific values from JSON, you’ll typically use the Set node or a lightweight Function node.
Method 1: Using the Set Node
- Add a Set Node below your HTTP Request (or any node that outputs JSON).
- Click on “Add Value”.
- Choose “String”, unless you know the value is a number or boolean.
- In the Value field, click the gears icon and choose “Add Expression”.
- Write this expression:
{{$json["data"]["author"]["email"]}}
This syntax navigates to the email inside the author object.
You can also simplify using dot notation:
{{$json["data.author.email"]}}
Method 2: Using the Function Node (Optional but Powerful)
If you prefer using a Function node to extract and reshape data:
- Add a Function node.
- Inside the function, use the following code:
return [
{
json: {
email: $json.data.author.email,
title: $json.data.title
}
}
];
This creates a new JSON object with just the values you care about.
Step 3: Use the Extracted Value Elsewhere in Your Workflow
Once you've isolated the value using a Set or Function node, it becomes easy to use it in other parts of your workflow:
- Send an email using this value in the Email node
- Pass it to another API using HTTP Request
- Store it in Airtable, Notion, or Google Sheets
Here’s a visual table to help remember how to access nested values:
| JSON Path | Expression |
|---|---|
Top-level field status |
{{$json["status"]}} |
Nested field data.title |
{{$json["data"]["title"]}} |
Deep field data.author.email |
{{$json["data"]["author"]["email"]}} or {{$json["data.author.email"]}} |
First item in an array roles[0] |
{{$json["user"]["roles"][0]}} |
Pro Tips for Extracting JSON Values
Use Expression Preview
When typing an expression like {{$json["data"]["title"]}}, you can click the ▶ (execution preview) icon to confirm if the value is being read correctly. This is a great debugging tool.
Loop Through Arrays
If you need to extract a specific value from each item in an array, use an Item Lists Loop or loop through array items with a Function or SplitInBatches node.
Avoid Common Mistakes
- Always check for the correct JSON path
- Use square brackets around properties with special characters or spaces
- Make sure the value exists (you can use optional chaining like
$json?.data?.author?.emailin Function nodes with JavaScript)
Mini Use Case: Send User Email to Google Sheets
Let’s say you receive webhook data from a signup form, and you want to capture the user’s email and send it to Google Sheets.
- Add a Webhook node to receive the form data (e.g., JSON like
{ "user": { "email": "user@example.com" } }) - Add a Set Node → Use expression
{{$json["user"]["email"]}}to assign to "UserEmail" - Connect a Google Sheets node and map the “UserEmail” value to a spreadsheet column
If you're not familiar with connecting Google apps, check out this Google Sheets n8n integration guide.
Handling Complex JSON with Dynamic Keys
Sometimes the structure changes or contains variable keys. In those cases, consider using the Function node to iterate through entries or use conditional logic to check if keys exist.
const keys = Object.keys($json.response);
return [
{
json: {
firstKey: keys[0],
value: $json.response[keys[0]]
}
}
];
This code helps when fields are unpredictable, such as dynamic fields in third-party webhook payloads.
Bonus: Use Case with OpenAI or ChatGPT
When integrating with AI tools like OpenAI via the API, the response is usually JSON-based. For example:
{
"choices": [
{
"text": "This is the generated text."
}
]
}
To extract the response:
{{$json["choices"][0]["text"]}}
You can check out how to use ChatGPT with n8n if you're building AI-based workflows.
FAQ
How do I extract a nested value like user.profile.address.city?
Use dot notation or bracketed expressions:
{{$json["user"]["profile"]["address"]["city"]}}
Or:
{{$json["user.profile.address.city"]}}
Can I access multiple values at once?
Yes. Use a Function node to combine multiple fields into a new JSON object or use multiple fields in a Set node.
What happens if the value doesn’t exist?
If a field is missing, n8n may throw an error. To prevent this, use optional chaining in Function nodes or validate the data before using it.
Is there a way to loop through all items in an array?
Yes. Use a SplitInBatches node or refer to this guide on looping arrays in n8n.
Can I extract values from files or binary JSON?
Not directly. You’ll first need to parse the content into a JSON format using a Function or HTTP Request node if the JSON is embedded in a file.
Understanding how to extract specific values from JSON in n8n is a game-changer for anyone working with data-driven automation. Once you master this foundation, building advanced workflows across APIs, spreadsheets, chatbots, and AI tools becomes significantly easier.
Copy-paste templates.
Beginner friendly.