# (v2.2 watcher ES) Convert complete payload to json to send via webhook

**URL:** <https://discuss.elastic.co/t/v2-2-watcher-es-convert-complete-payload-to-json-to-send-via-webhook/61205>\
**Category:** Elasticsearch\
**Tags:** elastic-stack-alerting\
**Created:** [September 22, 2016, 6:13am UTC](https://discuss.elastic.co/t/v2-2-watcher-es-convert-complete-payload-to-json-to-send-via-webhook/61205 "2016-09-22T06:13:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pransh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pransh/32/12806_2.png) [@Pransh](https://discuss.elastic.co/u/Pransh)\
**Post date:** [September 22, 2016, 6:13am UTC](https://discuss.elastic.co/t/v2-2-watcher-es-convert-complete-payload-to-json-to-send-via-webhook/61205/1 "2016-09-22T06:13:00Z")

</div>

HI @spinscale

Please help me with this  
i am using watcher 2.2 with es 2.2.0

Cannot upgrade, complete setup is in this version

I want to send the entire payload in the json format via webhook so that python can recieve it in the json object at the other end, i am using it with basic cluster health example but not able to convert the payload to json format

"condition" : {  
"compare" : {  
"ctx.payload.status" : { "eq" : "red" }  
}  
},  
"transform" : {  
"script" : "return [body: groovy.json.JsonOutput.toJson(ctx.payload.hits.hits)]"  
},  
"actions" : {  
"my\_webhook" : {  
"webhook" : {  
"scheme" : "http",  
"method" : "POST",  
"headers" : {  
"Content-Type" : "application/json"  
},  
"host" : "hostnamet",  
"port" : 1234,  
"path": "/try",  
"body" : "data: {{ctx.payload.body}}"  
}  
}  
}  
}'

help me with this

---

<div class="post-metadata">

**Author:** ![Pransh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pransh/32/12806_2.png) [@Pransh](https://discuss.elastic.co/u/Pransh)\
**Post date:** [September 22, 2016, 6:26am UTC](https://discuss.elastic.co/t/v2-2-watcher-es-convert-complete-payload-to-json-to-send-via-webhook/61205/3 "2016-09-22T06:26:49Z")

</div>

Done, was sending in wrong format in body.

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [September 26, 2016, 10:44am UTC](https://discuss.elastic.co/t/v2-2-watcher-es-convert-complete-payload-to-json-to-send-via-webhook/61205/4 "2016-09-26T10:44:56Z")

</div>

Hey,

as the groovy version used in elasticsearch is not containing that `JsonOutput` class, you cannot call it either. You would either need to create that JSON manually in the output, but I highly urge you to upgrade to 2.4, so you wont have any problems using the `{{#toJson}}` mustache directive.

--Alex

---

<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:42pm UTC](https://discuss.elastic.co/t/v2-2-watcher-es-convert-complete-payload-to-json-to-send-via-webhook/61205/5 "2017-07-06T13:42:47Z")

</div>


