# Prettify Watcher JSON Response

**URL:** <https://discuss.elastic.co/t/prettify-watcher-json-response/250947>\
**Category:** Elasticsearch\
**Tags:** elastic-stack-alerting\
**Created:** [October 5, 2020, 8:27am UTC](https://discuss.elastic.co/t/prettify-watcher-json-response/250947 "2020-10-05T08:27:48Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Porton](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/porton/32/47961_2.png) [@Porton](https://discuss.elastic.co/u/Porton)\
**Post date:** [October 5, 2020, 8:27am UTC](https://discuss.elastic.co/t/prettify-watcher-json-response/250947/1 "2020-10-05T08:27:48Z")

</div>

What is the best way to pretty JSON response from Elasticsearch Watch ?

Currently doing webhook to MS Teams,

```auto
body": "{ title: 'Server Metrics Alert', text: '{{#toJson}}ctx.payload.hits{{/toJson}}' }",

```

Everything works, however (as expected) ctx.payload.hits is NOT pretty.

What is the easiest way to prettify that ctx.payload.hits ?

---

<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:** [October 5, 2020, 9:46am UTC](https://discuss.elastic.co/t/prettify-watcher-json-response/250947/2 "2020-10-05T09:46:37Z")

</div>

Use a [transform](https://www.elastic.co/guide/en/elasticsearch/reference/7.9/transform-script.html) in your action to get the data into a proper format first.

---

<div class="post-metadata">

**Author:** ![Porton](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/porton/32/47961_2.png) [@Porton](https://discuss.elastic.co/u/Porton)\
**Post date:** [October 8, 2020, 3:49am UTC](https://discuss.elastic.co/t/prettify-watcher-json-response/250947/3 "2020-10-08T03:49:39Z")

</div>

The format is fine, just want to prettify the json text.

Do you see anything in transform that can be used to prettify JSON text?

---

<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:** [October 8, 2020, 8:31am UTC](https://discuss.elastic.co/t/prettify-watcher-json-response/250947/4 "2020-10-08T08:31:38Z")

</div>

I don't see a way to do this right now, but soon you will be able to use `Json.dump()` with a prettyfying option in Painless.

See [https://github.com/elastic/elasticsearch/pull/63278](https://github.com/elastic/elasticsearch/pull/63278)

---

<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:** [November 5, 2020, 8:31am UTC](https://discuss.elastic.co/t/prettify-watcher-json-response/250947/5 "2020-11-05T08:31:46Z")

</div>

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