Locoia
Search…
Dict Helper
Replace, add or filter for dictionaries or lists a.k.a. JSON objects

Why do I need a Dict & List Helper? Well, to manipulate dictionaries and

Dictionaries, which are basically JSON objects converted into something that a program can better work with and lists are likely the most used to forms of transferring data among programs and between browsers and servers.
Let's set some basic ground work first!

1. Dictionaries (Dict)

It's like JSON, looks something like this:
1
{
2
"users": [
3
{user1 ... some more JSON},
4
{user2 ... some more JSON},
5
{user3 ... some more JSON}
6
...
7
]
8
}
Copied!

2. Lists

List looks something like this [ 1, 2, 3]. this one just contains numbers. A list of strings (text) would look something like this and contain quotes " around the strings:
1
[ "Munich", "Berlin", "Frankfurt"]
Copied!
So good so far. A CSV file with city names in the 1st row and population in the 2nd row would be expressed as a list of list and look like this:
1
[ [ "Munich", "Berlin", "Frankfurt"], [ "1,45 Millionen", "3,575 Millionen", "736.414"] ]
Copied!

Functions of the list and dict helper:

1. Replacing fields in lists or dictionaries

Replacing fields in dictionaries
As per the above screenshot, we replace the field `first_name` in the JSON / dictionary response of Zendesk with my_new_name. E.g. this (zend1.user) can look like this:
1
{
2
"user": {
3
"first_name": "Max",
4
"last_name": "Miller",
5
"email": "[email protected]"
6
}
7
}
Copied!
After replacing it looks like this:
1
{
2
"user": {
3
"first_name": "my_new_name",
4
"last_name": "Miller",
5
"email": "[email protected]"
6
}
7
}
Copied!

2. Replacing fields in lists

Replacing fields in lists
As per the above screenshot, we replace the eights column (item) in a list (in this case in a looper) with my_new_name. E.g. this (loo1) can look like this:
1
[
2
"Berlin",
3
"Hamburgstraße 12",
4
20299,
5
78,
6
"male",
7
"student",
8
"Miller",
9
"Max"
10
]
Copied!
Replacing it returns:
1
[
2
"Berlin",
3
"Hamburgstraße 12",
4
20299,
5
78,
6
"male",
7
"student",
8
"Miller",
9
"my_new_name"
10
]
Copied!

3. Adding fields to a dictionary

The above adds the field age = 27 to the dictionary. E.g. this (zend1.user) can look like this:
1
{
2
"user": {
3
"first_name": "Max",
4
"last_name": "Miller",
5
"email": "[email protected]"
6
}
7
}
Copied!
Will become after adding age:
1
{
2
"user": {
3
"first_name": "Max",
4
"last_name": "Miller",
5
"email": "max.mi[email protected]",
6
"age": 27
7
}
8
}
Copied!

4. Adding fields to a list

The above adds 27 to the list. E.g. this (loo1) can look like this:
1
[ "Berlin", "Hamburgstraße 12", 20299, 78, "male", "student", "Miller", "Max" ]
Copied!
Will become after adding:
1
[ "Berlin", "Hamburgstraße 12", 20299, 78, "male", "student", "Miller", "Max" , 27]
Copied!

5. Filtering a list (e.g. CSV) or dictionary (dict), a.k.a. JSON

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:
1
{
2
"tickets": [
3
{ticket1 ... some more JSON},
4
{ticket2 ... some more JSON},
5
{ticket3 ... some more JSON}
6
...
7
]
8
}
Copied!
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:
1
item.requester_id == 12345
Copied!
An alternative notation which would yield the same result would beHTML
1
12345 in item.tags
Copied!
Note that you cannot use the item parameter in combination with Jinja, here need you to use Python instead.
Last modified 1mo ago