JSON Filter Component
Use the JSON Filter component to reduce large JSON objects to only the fields you need. It's an essential tool for cleaning up noisy API responses, simplifying data for downstream components, and preventing context window overloads with LLMs.
Why this matters
What You’ll Configure
- Define Filter Parameters
- Provide the JSON Input
- Handle the Filtered Output
- Example Usage
- Best Practices
- Troubleshooting Tips
- What to Try Next
Step 1: Define Filter Parameters
Specify the exact keys you want to keep from the original JSON object. All other keys will be discarded.
Setting | Required? | Description | Notes |
---|---|---|---|
Filter Parameters | Yes | A comma-separated list of keys to retain in the output. | To keep a nested key, you must also include all of its parent keys. |
Nested Keys
Step 2: Provide the JSON Input
This component requires a single input: the JSON object you want to filter.
Input | Required? | Description | Notes |
---|---|---|---|
Input | Yes | The JSON object or array of objects to be filtered. | Can be passed from an API Call, Code component, or any other step. |
Step 3: Handle the Filtered Output
The component outputs a new, smaller JSON object containing only the keys you specified.
Output | Description | Data Structure |
---|---|---|
Output | The new JSON object containing only the retained fields. | A valid JSON object. |
Step 4: Example Usage
Imagine you get a large user object from an API call, but you only need the user's name and their shipping address.
Original JSON Input:
{
"user": {
"id": "usr_12345",
"name": "Jane Doe",
"profile": {
"email": "jane.doe@example.com",
"phone": "555-123-4567",
"avatar_url": "[https://example.com/avatar.jpg](https://example.com/avatar.jpg)"
},
"address": {
"shipping": {
"street": "123 Main St",
"city": "Anytown"
},
"billing": {
"street": "456 Oak Ave",
"city": "Someplace"
}
},
"metadata": {
"last_login": "2024-01-01T12:00:00Z",
"account_tier": "gold"
}
}
}
Filter Parameters Setting:
user, user.name, user.address, user.address.shipping
Filtered JSON Output:
{
"user": {
"name": "Jane Doe",
"address": {
"shipping": {
"street": "123 Main St",
"city": "Anytown"
}
}
}
}
Best Practices
- Filter Early: Place the
JSON Filter
component immediately after an API Call to reduce the data size for all subsequent steps. - Be Specific: Only filter for the data you absolutely need. This keeps your agent's memory usage low and processing fast.
- Use for LLM Prep: Always filter large JSON objects before passing them to a GenAI LLM to save on token costs and improve model focus.
- Test with Debug Mode: Use the Debug panel to inspect the input and output, ensuring your filter parameters are correct.
Troubleshooting Tips
If your filter isn't working...
What to Try Next
- Chain an API Call into a
JSON Filter
to immediately clean the response. - Pass the filtered
Output
to a GenAI LLM Component to have it summarize only the essential information. - Use the filtered object as the input for a ForEach Component to loop through a cleaned list of items.