# Web action JSON issue (again)

**URL:** <https://discuss.elastic.co/t/web-action-json-issue-again/58013>\
**Category:** Elasticsearch\
**Tags:** elastic-stack-alerting\
**Created:** [August 15, 2016, 9:28am UTC](https://discuss.elastic.co/t/web-action-json-issue-again/58013 "2016-08-15T09:28:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![paulkeogh](https://avatars.discourse-cdn.com/v4/letter/p/8dc957/32.png) [@paulkeogh](https://discuss.elastic.co/u/paulkeogh)\
**Post date:** [August 15, 2016, 9:28am UTC](https://discuss.elastic.co/t/web-action-json-issue-again/58013/1 "2016-08-15T09:28:52Z")

</div>

Hi,

I have run into the same problem as several other posters on this topic.

It appears that the webhook action is removing the JSON formatting on the search results;

I am using sense to test and I can see that the search result looks like;

```
"payload": {
  "_shards": {
    "total": 5,
    "failed": 0,
    "successful": 5
  },
  "hits": {
    "hits": [],
    "total": 0,
    "max_score": 0
  },
  "took": 6,
  "timed_out": false,
  "aggregations": {
    "2": {
      "buckets": []
    }
  }
},

```

whereas the webhook action looks like;

```
      "body": "{_shards={total=5, failed=0, successful=5}, hits={hits=[], total=0, max_score=0.0}, took=6, timed_out=false, aggregations={2={buckets=[]}}}"
    },

```

where I have used

`"body": "{{ctx.payload}}"`

The is problematic when trying to feed the results into the http logstash input where the default codec is JSON.

Any suggestions ?

---

<div class="post-metadata">

**Author:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [August 17, 2016, 9:18am UTC](https://discuss.elastic.co/t/web-action-json-issue-again/58013/2 "2016-08-17T09:18:49Z")

</div>

Hi @paulkeogh

I don't have a good solution for you today, but there is one coming. There are two problems here:

- `ctx.payload` is being stringified as a Java hashmap, which clearly isn't valid JSON
- The `body` is a string instead of JSON

The first problem will be solved by the new `toJson` helper which will be [available in 2.4.0](https://github.com/elastic/elasticsearch/pull/19153), and the second can be solved by using Logstash's [`json` filter](https://www.elastic.co/guide/en/logstash/current/plugins-filters-json.html).

So once 2.4.0 is out, instead of doing

```
"body": "{{ctx.payload}}"

```

you could do:

```
"body": { "my_field": "{{#toJson}}ctx.payload{{/toJson}}" }

```

and then use the json filter to decode the `my_field` field

---

<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:43pm UTC](https://discuss.elastic.co/t/web-action-json-issue-again/58013/3 "2017-07-06T13:43:27Z")

</div>


