Adding Data within Scenario

I achieved a solution, but I find it very complicated. If there is any better way to do it, I would be happy for advice:
I have this data structure out of a API:

[{ "a":"value1", "b":"value3, "parties":[{ "email":"abc@domain1.com", "name":"david smith" },{ "email":"def@domain2.com", "name":"Martha Smith" }] }]

This data is going to be saved in a table. I need to add one field called “typ”. The content of the field is “apple” in case one of the domains ends on “domain1.com”. If not it should be “pear”:
for example:

[{ "a":"value1", "b":"value3, "participants":[{ "email":"abc@domain1.com", "name":"david smith" },{ "email":"def@domain2.com", "name":"Martha Smith" }], "typ":"apple" }]

To achieve this I added the two modules “Create JSON” and “Parse JSON”.

In the field “typ” of the “create JSON” module, I’ve included this function:
{{if(contains(toString(map(7.participants; "email")); "domain1.com"); "apple"; "pear")}}

It looks way to complicated to me, however, as a beginner, I did not find a easier way to achieve this.

Welcome to the Make community!

Yes, that is possible. You’ll need just one module:

Output:

Screenshot_2024-02-21_220207

Give it a go and let us know if you have any issues!

3 Likes

Thanks, I think I found a more elegant solution by using the “set multiple variables” module. It does not get incorporated in the JSON directly, however I can use the value later on. – still learning.

1 Like