Dict Helper
Replace, add or filter for dictionaries or lists a.k.a. JSON objects
Overview
Dict Helper is not only one of the most popular tools, but it is also a powerful tool for Flow. It is capable of storing values, filtering them, parsing Jinja expressions, and much more.
What is essential for you to understand
Dictionaries, essentially JSON objects adapted for efficient program communication, along with lists, constitute the most commonly employed methods for transferring data between programs and bridging the gap between browsers and servers.
1. Dictionaries (Dict)
A dictionary is a structure that is essentially a list of key: value pairs.
2. Lists
A list, similar to an array, is a versatile data structure designed for storing collections of items. Lists can accommodate a wide range of data types, including:
Numbers (both floating-point and integers)
Strings
Nested lists
Dictionaries
This flexibility makes lists a fundamental tool for managing and organizing various types of data."
3. Jinja expressions
Jinja is a powerful templating engine designed for Python. It seamlessly integrates with Dict Helper, allowing you to effortlessly execute logic by passing Jinja expressions directly. You can learn more here
Actions
1. Define variables for later use
This action has only one input that accepts dictionaries, lists, and Jinja expressions.
It allows you to reference data from Previous Steps, File Uploads, and Environment Variables within your workflow, enabling you to execute custom logic.
In this example, the variable contacts
comes from a previous step:
2. Filter List V2
The enhanced version of the Filter makes it effortless to apply filtering in a no/low-code manner. Filtering is carried out using a variety of predefined filter operators tailored to different data types. Some of them:
Exists
Equal to
Greater than
Less than
Contains
Is empty
3. Remove list from lists (flatten list
)
flatten list
)Nested lists
Dictionaries
For instance: if you have a list like
you get [1, 2, 3, 4, 5, 6, 7, 8, 9]
back.
4. Store Value
Add any kind of value to a dictionary
5. Add string to the dictionary
This feature enables you to append a new field with a specified value to an existing dictionary. For instance, if you have a Zendesk user object containing first_name
and last_name
, you can easily include the age
by specifying both the Field name and the desired Content:
6. Add string to list
It allows you to add a new string to an existing list.
7. Replacing fields in lists or dictionaries
With this action, you can replace a value in the specified place.
For example, you have a user (zend1.user):
And you want to replace the value of the field first_name
in the JSON / dictionary response of Zendesk with my_new_name
:
After replacing:
Replace a value in the list: Similarly to the previous example you need to specify the destination - index to access n
element in the list. So to replace the user's email here you need to enter it's index [2]
8. Update value
Update any kind of value in a dictionary
9. Append Value
This is very similar to #6.-add-string-to-listbut more powerful It allows you to add an entire row or object to a list.
10. Combine Lists
This helps you to unite two lists in one
Example:
will be united into
11. Convert List Of Dicts To List Of Lists
Converts list of dicts (JSON objects):
to list of lists:
12. Filtering
For a large list, larger than 50k entries or 5 MB, please use the Spreadsheet helper with action Query spreadsheet, as it can better handle large data.
You can also use the Jinja filter selectattr
to filter without having to use an action.
Filtering a list
will most likely be used a lot for CSV files or e.g. GoogleSheet content that is a list of lists. Please see the section here on filtering CSVs here.
Filtering a JSON / dictionary (dict)
As an example, let's say you want to filter a list of Freshdesk or Zendesk tickets. The response JSON of an API would look like this:
The corresponding connector setup looks like this:
As a list reference in this case, you would provide zen1.tickets in order to only get the list of tickets, because as you can see, within the above JSON object is again a list, indicated by the squared brackets [ ]. So essentially, you could say the above is a JSON object that wraps a list of ticket objects, which are again JSON.
If you want to filter for a particular data record e.g. after pulling all your Zendesk tickets, you want to get all tickets where the requester_id
is 12345
, you could filter for:
An alternative notation which would yield the same result would be HTML
More examples:
Note that you cannot use the item
parameter in combination with Jinja, here need you to use Python instead.
Last updated