# Assign String to a Collection

**URL:** <https://community.make.com/t/assign-string-to-a-collection/4004>\
**Category:** Questions\
**Created:** [August 31, 2022, 10:07am UTC](https://community.make.com/t/assign-string-to-a-collection/4004 "2022-08-31T10:07:38Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Beaver](https://avatars.discourse-cdn.com/v4/letter/b/a698b9/32.png) [@Beaver](https://community.make.com/u/Beaver)\
**Post date:** [August 31, 2022, 10:07am UTC](https://community.make.com/t/assign-string-to-a-collection/4004/1 "2022-08-31T10:07:38Z")

</div>

Hi,  
Is it possible to assign a string to a collection directly and that Make parse it if it’s properly formated?  
Haven’t found a way/format that works.

Example:

```auto
Collection Foo
   - Bar1: String
   - Bar2: Number

Field1: Foo

```

Have something like:  
`Field1 <-- { ["Bar1", "Beer"], ["Bar2", "2534"]}`

Obviously the structure will be much more complicated and dynamic, hence the need for a direct assignment.

Many thanks to all

---

<div class="post-metadata">

**Author:** ![alex.newpath](https://dub1.discourse-cdn.com/flex013/user_avatar/community.make.com/alex.newpath/32/84_2.png) [@alex.newpath](https://community.make.com/u/alex.newpath)\
**Post date:** [August 31, 2022, 11:19am UTC](https://community.make.com/t/assign-string-to-a-collection/4004/2 "2022-08-31T11:19:34Z")

</div>

Looks like you’re creating a collection of arrays. `Tocollection()` would work and you can create the arrays with a `map()`.

Show us what you’ve tried already and we can get you further.

---

<div class="post-metadata">

**Author:** ![Beaver](https://avatars.discourse-cdn.com/v4/letter/b/a698b9/32.png) [@Beaver](https://community.make.com/u/Beaver)\
**Post date:** [August 31, 2022, 11:38am UTC](https://community.make.com/t/assign-string-to-a-collection/4004/3 "2022-08-31T11:38:17Z")

</div>

Actually, I’ve tried every permutation of every function :'D

I’m just trying to create a Collection with two fields in this example  
It should end as:

```auto
{
  "Bar1":"Beer1",
  "Bar2":2534
}

```

`toCollection` (very poorly documented, I spent hours trying to understand how it treated the input data), takes in input an array, each row of the array being a key-value pair representing `FieldName` and `FieldValue` for the target collection. That’s why I was trying to format my input string as ` { [“Bar1”, “Beer”], [“Bar2”, “2534”]}`

But It can’t transform the string into a collection it seems. `toCollection( { [“Bar1”, “Beer”], [“Bar2”, “2534”]})` fails to execute too.

What works is `toCollection(add(add(),add())` but it works just for this simple example, and in my case I have an array of indefinite number of collections. As there is no iterative or recursive functions, I can’t do it directly in one field. Hence my search for a string pattern allowing to assign this string to a Collection field.

Hope this is clearer 🙂

---

<div class="post-metadata">

**Author:** ![alex.newpath](https://dub1.discourse-cdn.com/flex013/user_avatar/community.make.com/alex.newpath/32/84_2.png) [@alex.newpath](https://community.make.com/u/alex.newpath)\
**Post date:** [August 31, 2022, 1:30pm UTC](https://community.make.com/t/assign-string-to-a-collection/4004/4 "2022-08-31T13:30:54Z")

</div>

Have you tried an iterator (under tools) that sends each part of your collection and then have a set variable step that adds to the array iteratively. There’s no recursion but there is an iterator.

---

<div class="post-metadata">

**Author:** ![Beaver](https://avatars.discourse-cdn.com/v4/letter/b/a698b9/32.png) [@Beaver](https://community.make.com/u/Beaver)\
**Post date:** [August 31, 2022, 1:46pm UTC](https://community.make.com/t/assign-string-to-a-collection/4004/5 "2022-08-31T13:46:09Z")

</div>

Yep, but I wanted to overload my scenario with lots of modules, and wanted to do that inline in one script.  
I’m trying to do it right now by generating a JSON string and parsing it with the JSON parser module. It just adds 1 module. Just having formatting issues.

---

<div class="post-metadata">

**Author:** ![alex.newpath](https://dub1.discourse-cdn.com/flex013/user_avatar/community.make.com/alex.newpath/32/84_2.png) [@alex.newpath](https://community.make.com/u/alex.newpath)\
**Post date:** [August 31, 2022, 2:12pm UTC](https://community.make.com/t/assign-string-to-a-collection/4004/6 "2022-08-31T14:12:50Z")

</div>

> [@Beaver](#):
>
> Yep, but I wanted to overload my scenario with lots of modules, and wanted to do that inline in one script.

It’s really hard to overload Make. Easy to read and manage scenarios are broken down into multiple modules. If you are trying to design your scenario to conserve operations you may really be spending a ton of time trying to optimize for no really good reason. 1000 operations for free will be burned just testing.

Use an iterator after Parse Json or just get the raw array data and eliminate the use of json.

---

<div class="post-metadata">

**Author:** ![Beaver](https://avatars.discourse-cdn.com/v4/letter/b/a698b9/32.png) [@Beaver](https://community.make.com/u/Beaver)\
**Post date:** [August 31, 2022, 2:45pm UTC](https://community.make.com/t/assign-string-to-a-collection/4004/7 "2022-08-31T14:45:33Z")

</div>

My mistake, I **didn’t want** to overload my scenario 😃  
Yep, just generating the string and parsing it with JSON Parse delivers the objects.  
Thanks!

---

<div class="post-metadata">

**Author:** ![Beaver](https://avatars.discourse-cdn.com/v4/letter/b/a698b9/32.png) [@Beaver](https://community.make.com/u/Beaver)\
**Post date:** [August 31, 2022, 7:55pm UTC](https://community.make.com/t/assign-string-to-a-collection/4004/8 "2022-08-31T19:55:50Z")

</div>

So, I finally did it this way:  
Generate a JSON formatted string  
Use the JSON parser module to parse it into an array of collections.  
1 step 🙂

---

<div class="post-metadata">

**Author:** ![Make\_Bot](https://dub1.discourse-cdn.com/flex013/user_avatar/community.make.com/make_bot/32/14661_2.png) [@Make\_Bot](https://community.make.com/u/Make_Bot)\
**Post date:** [September 7, 2023, 2:41pm UTC](https://community.make.com/t/assign-string-to-a-collection/4004/9 "2023-09-07T14:41:01Z")

</div>

This topic was automatically closed because it's resolved or inactive. Please, start a new topic.


