# Webhook action: Hits collection not JSON

**URL:** <https://discuss.elastic.co/t/webhook-action-hits-collection-not-json/24568>\
**Category:** Elasticsearch\
**Tags:** elastic-stack-alerting\
**Created:** [June 29, 2015, 7:13pm UTC](https://discuss.elastic.co/t/webhook-action-hits-collection-not-json/24568 "2015-06-29T19:13:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bboward](https://avatars.discourse-cdn.com/v4/letter/b/ce7236/32.png) [@bboward](https://discuss.elastic.co/u/bboward)\
**Post date:** [June 29, 2015, 7:13pm UTC](https://discuss.elastic.co/t/webhook-action-hits-collection-not-json/24568/1 "2015-06-29T19:13:07Z")

</div>

I have a watch that uses the webhook action to post the hits from my search input. The resulting data is not JSON, but is in a different serialized format that is harder to parse. Is it possible to emit the actual JSON documents found in the search? If not, how are people handling these results?

I think this is the same question here: [JSON Webhooks](https://discuss.elastic.co/t/json-webhooks/1024/5)

Example webhook action:

```
"actions": {
  "my_webhook": {
    "webhook": {
      "scheme": "http",
      "host": "my.host",
      "port": 80,
      "method": "post",
      "path": "/path",
      "body": {
        "inline": "{{ctx.payload.hits.hits}}"
      }
    }
  }
}
```

This is the data in the POST body:

```
{0={_type=cat, _source={name=Garfield}, _id=1, _index=pets, _score=1.0}, 1={_type=dog, _source={name=Odie}, _id=2, _index=pets, _score=1.0}, 2={_type=mouse, _source={name=Mortimer, the unknown Mouse}, _id=3, _index=pets, _score=1.0}}
```

---

<div class="post-metadata">

**Author:** ![uboness](https://avatars.discourse-cdn.com/v4/letter/u/96bed5/32.png) [@uboness](https://discuss.elastic.co/u/uboness)\
**Post date:** [June 29, 2015, 9:34pm UTC](https://discuss.elastic.co/t/webhook-action-hits-collection-not-json/24568/2 "2015-06-29T21:34:03Z")

</div>

Hi,

Yes, our `mustache` impl is limited with that regard. You can use a `script` transform to convert any part in the payload to json string:

```auto
{
    ...
    "transform" : {
        "script" : "return [body: groovy.json.JsonOutput.toJson(ctx.payload.hits.hits)]"
    },
    "actions" : {
     ...
    }
}

```

---

<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:** [July 6, 2017, 1:49pm UTC](https://discuss.elastic.co/t/webhook-action-hits-collection-not-json/24568/3 "2017-07-06T13:49:22Z")

</div>


