# Decode ascii hex from string or Convert Charset of a Field on the fly (filters)

**URL:** <https://discuss.elastic.co/t/decode-ascii-hex-from-string-or-convert-charset-of-a-field-on-the-fly-filters/51540>\
**Category:** Logstash\
**Created:** [June 1, 2016, 9:48am UTC](https://discuss.elastic.co/t/decode-ascii-hex-from-string-or-convert-charset-of-a-field-on-the-fly-filters/51540 "2016-06-01T09:48:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jonathanpmartins](https://avatars.discourse-cdn.com/v4/letter/j/aeb1de/32.png) [@jonathanpmartins](https://discuss.elastic.co/u/jonathanpmartins)\
**Post date:** [June 1, 2016, 9:48am UTC](https://discuss.elastic.co/t/decode-ascii-hex-from-string-or-convert-charset-of-a-field-on-the-fly-filters/51540/1 "2016-06-01T09:48:49Z")

</div>

I have a case, that a numb cliente sends me a http request with all UTF-8 chaset, but the payload comes with ascii hex, like: "\x22", "\xC3" "\xA2", and so on...

How can I DECODE only this string field, so I can proceed with my filter chain?

Example of the received JSON received:

```
    {\x22appid\x22:\x22000000000000001\x22,\x22devid\x22:\x22CN6Z8Eka3FSQ9IA\x22,\x22hash\x22:\x226DA58601C8DF15A\x22,\x22hwid\x22:\x22938F281AE5EB32B1\x22,\x22info\x22:{\x22city\x22:\x22Uberl\xC3\xA2ndia\x22,\x22country\x22:\x22Brasil\x22,\x22neighborhood\x22:\x22Alto Umuarama\x22,\x22state\x22:\x22Minas Gerais\x22,\x22country_code\x22:\x22BR\x22},\x22locations\x22:[{\x22lat\x22:-18.8827592,\x22lng\x22:-48.2485458,\x22time\x22:1456682328}]}

```

Using **gsub** I cant replace some codes, but this seems not to be the best solution. And even removing the "\x22" codes em put in place a double quote, logstash put a backsh before that _"_

Example using gsub =\> ["field", "\x22", '"'], returns

```
      {\"appid\":\"000000000000001\",\"devid\":\"CN6Z8Eka3FSQ9IA\",\"hash\":\"6DA58601C8DF15A\",\"hwid\":\"938F281AE5EB32B1\",\"info\":{\"city\":\"Uberl\\xC3\\xA2ndia\",\"country\":\"Brasil\",\"neighborhood\":\"Alto Umuarama\",\"state\":\"Minas Gerais\",\"country_code\":\"BR\"},\"locations\":[{\"lat\":-18.8827592,\"lng\":-48.2485458,\"time\":1456682328}]}

```

Ooohh, backssashes... afff heheheehe

You can see that the backslashes don't ge away, I thik this is causing the "\_jsonparsefailure" error message.

Do I forget something, like a rookie thin? To many hours working... ehehhehe

Regards!

---

<div class="post-metadata">

**Author:** ![jonathanpmartins](https://avatars.discourse-cdn.com/v4/letter/j/aeb1de/32.png) [@jonathanpmartins](https://discuss.elastic.co/u/jonathanpmartins)\
**Post date:** [June 1, 2016, 10:14am UTC](https://discuss.elastic.co/t/decode-ascii-hex-from-string-or-convert-charset-of-a-field-on-the-fly-filters/51540/2 "2016-06-01T10:14:17Z")

</div>

If it helps, here is what I trying to do:

```
            mutate {
                gsub => ['body', '\\x22', '"']
            }
            json {
                source => "body"
                target => "data"
            }
```

---

<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, 4:55am UTC](https://discuss.elastic.co/t/decode-ascii-hex-from-string-or-convert-charset-of-a-field-on-the-fly-filters/51540/3 "2017-07-06T04:55:02Z")

</div>


