# If statement if text aggregator is in last iteration

**URL:** <https://community.make.com/t/if-statement-if-text-aggregator-is-in-last-iteration/4993>\
**Category:** Questions\
**Created:** [November 8, 2022, 9:37pm UTC](https://community.make.com/t/if-statement-if-text-aggregator-is-in-last-iteration/4993 "2022-11-08T21:37:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ingo](https://avatars.discourse-cdn.com/v4/letter/i/e19adc/32.png) [@Ingo](https://community.make.com/u/Ingo)\
**Post date:** [November 8, 2022, 9:37pm UTC](https://community.make.com/t/if-statement-if-text-aggregator-is-in-last-iteration/4993/1 "2022-11-08T21:37:35Z")

</div>

Hello,

I am trying to create a JSON from a MySQL select call to use in an API call to HubSpot to update contacts in a batch.

I can´t figure out to create the required JSON for this.

At first I tried to use the Text Aggregator which would work fine, but I don´t know how to define that the last collection should not have a comma at the end.  
If someone can give me a hint, the issue would be solved.

I tried the JSON aggregator but the format never ends up like it is needed.

So here is what I need:

```auto
{
  "inputs": [
    {
      "id": "1",
      "properties": {
        "company": "Biglytics",
        "email": "bcooper@biglytics.net",
        "firstname": "Bryan",
        "lastname": "Cooper",
        "phone": "(877) 929-0687",
        "website": "biglytics.net"
      },
    {
      "id": "2",
      "properties": {
        "company": "Biglytics",
        "email": "bcooper@biglytics.net",
        "firstname": "Bryan",
        "lastname": "Cooper",
        "phone": "(877) 929-0687",
        "website": "biglytics.net"
      },
    }
  ]
}

```

With the JSON aggregator I only managed to get the following formats

```auto
[
   {
      "inputs":[
         "1"
      ],
      "properties":{
        "company": "Biglytics",
        "email": "bcooper@biglytics.net"
      }
   },
   {
      "inputs":[
         "2"
      ],
      "properties":{
        "company": "Biglytics",
        "email": "bcooper@biglytics.net"
      }
   }
]

```

```auto
[
   {
      "inputs":[
         {
            "id":"20095051",
            "properties":{
               "company": "Biglytics",
               "email": "bcooper@biglytics.net"
            }
         }
      ]
   },
   {
      "inputs":[
         {
            "id":"7833352",
            "properties":{
               "company": "Biglytics",
               "email": "bcooper@biglytics.net"
            }
         }
      ]
   }
]

```

I could get rid of the brackets like described here, but the general structure doesn´t match.

> [@robot How to get rid of \[brackets\] generated by the JSON aggregator in Make?](https://community.make.com/t/make-bot-tips-how-to-get-rid-of-brackets-generated-by-the-json-aggregator/2738):
>
> You can use the [substring function](https://www.make.com/en/help/functions/string-functions#substring--text--start--end-) in order to get rid of the unwanted [] brackets generated by the JSON aggregator. How to configure the function: ​ ​ The function ‘translated’ into words: From the text (in this case a JSON string), give me only characters 1 till the end of the string minus one character (length -1) ​The code to copy: {{substring(211.JSON String; 1; length(211.JSON String) - 1)}} Helpful Links: make [JSON Guide](https://apps.make.com/json)make [Using Function Guide](https://help.make.com/string-functions#substring--text--start--end-)

Thank you so much for you help,  
Ingo

---

<div class="post-metadata">

**Author:** ![Bjorn.drivn](https://dub1.discourse-cdn.com/flex013/user_avatar/community.make.com/bjorn.drivn/32/4503_2.png) [@Bjorn.drivn](https://community.make.com/u/Bjorn.drivn)\
**Post date:** [November 8, 2022, 9:44pm UTC](https://community.make.com/t/if-statement-if-text-aggregator-is-in-last-iteration/4993/2 "2022-11-08T21:44:45Z")

</div>

Hey @Ingo ,

So for the text aggregator you can take a look at this post I created:

> [@Aggregate items into a JSON collection](https://community.make.com/t/aggregate-items-into-a-json-collection/4960/2):
>
> @Kevin_Flaherty You can use a text aggregator? Or is it a different kind of value you are looking for. Here you setup the JSON, which then looks like this: You only have to add another opening and closing brackets for the JSON.

If you like to use the JSON module, there is a “generator” you can use for your structure. This generator allows you to easily get the structure you want. In this case you would have to use something like this:

```auto
{
	"inputs": [{
			"id": "1",
			"properties": {
				"company": "Biglytics",
				"email": "bcooper@biglytics.net",
				"firstname": "Bryan",
				"lastname": "Cooper",
				"phone": "(877) 929-0687",
				"website": "biglytics.net"
			}
		},
		{
			"id": "2",
			"properties": {
				"company": "Biglytics",
				"email": "bcooper@biglytics.net",
				"firstname": "Bryan",
				"lastname": "Cooper",
				"phone": "(877) 929-0687",
				"website": "biglytics.net"
			}
		}
	]
}

```

 ![Screenshot 2022-11-08 at 22.42.24](https://europe1.discourse-cdn.com/flex013/uploads/make/original/2X/9/9e429470f4f995bba2b2528dac430cd04050fba5.jpeg)

Instead of the structure you provided above (a few small fixes).

---

<div class="post-metadata">

**Author:** ![Ingo](https://avatars.discourse-cdn.com/v4/letter/i/e19adc/32.png) [@Ingo](https://community.make.com/u/Ingo)\
**Post date:** [November 8, 2022, 9:58pm UTC](https://community.make.com/t/if-statement-if-text-aggregator-is-in-last-iteration/4993/3 "2022-11-08T21:58:39Z")

</div>

Hi @Bjorn.drivn,

awesome. I actually found the post you linked and tried it.  
Instead of adding the comma myself I let [make.com](http://make.com) do it and it works like a charm.

I will also look into the solution with the JSON aggregator.

Thank you very much!  
Ingo

---

<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, 3:02pm UTC](https://community.make.com/t/if-statement-if-text-aggregator-is-in-last-iteration/4993/4 "2023-09-07T15:02:13Z")

</div>

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


