# Possible to have {{#context.hits}}{{.}}{{/context/hits}} as array?

**URL:** <https://discuss.elastic.co/t/possible-to-have-context-hits-context-hits-as-array/327811>\
**Category:** Kibana\
**Tags:** elastic-stack-alerting\
**Created:** [March 16, 2023, 6:43am UTC](https://discuss.elastic.co/t/possible-to-have-context-hits-context-hits-as-array/327811 "2023-03-16T06:43:42Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Maxim\_Afonin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/maxim_afonin/32/118509_2.png) [@Maxim\_Afonin](https://discuss.elastic.co/u/Maxim_Afonin)\
**Post date:** [March 16, 2023, 6:43am UTC](https://discuss.elastic.co/t/possible-to-have-context-hits-context-hits-as-array/327811/1 "2023-03-16T06:43:42Z")

</div>

I am preparing payload for the webhook to be sent when alert is generated by the rule. By using the following mustache template I am able to iterate through several documents get values from them:

```auto
{
	"content": "{{#context.hits}} alert_id: {{{_source.alert_id}}} resource: {{{_source.resource}}} timestamp: {{_source.timestamp}} {{/context.hits}}"
}

```

However, the returned data is a string value inside of JSON, something like this: Sent Payload:

```auto
{
"body" : {
         "content" : " alert_id: f1e1ddc7142c587d51dcaa453ed56ce3 resource: xxxxxx timestamp: 2023-03-15T13:59:13+00:00 alert_id: 1064565be1612303fe53b1cb952c34536 resource: xxxxxxy timestamp: 2023-03-15T13:35:09+00:00
      }
}

```

Is there anyway to have a line break and return this in something like this:

```auto

{
	"body": [{
			"alert_id": "1e1ddc7b49c587d51dcaab34ed56ce3",
			"resource": "xxxxxx",
			"timestamp": "2023-03-15T13:59:13+00:00"
		},
		{
			"alert_id": "106af45be164b03fe53453b952c34536",
			"resource": "xxxxxxy",
			"timestamp": "2023-03-15T13:35:09+00:00"
		}
	]
}

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [April 13, 2023, 6:44am UTC](https://discuss.elastic.co/t/possible-to-have-context-hits-context-hits-as-array/327811/2 "2023-04-13T06:44:15Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
