# How to convert hex to ascii in logstash?

**URL:** <https://discuss.elastic.co/t/how-to-convert-hex-to-ascii-in-logstash/365803>\
**Category:** Logstash\
**Created:** [August 30, 2024, 7:49am UTC](https://discuss.elastic.co/t/how-to-convert-hex-to-ascii-in-logstash/365803 "2024-08-30T07:49:18Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![lilyyy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lilyyy/32/51129_2.png) [@lilyyy](https://discuss.elastic.co/u/lilyyy)\
**Post date:** [August 30, 2024, 7:49am UTC](https://discuss.elastic.co/t/how-to-convert-hex-to-ascii-in-logstash/365803/1 "2024-08-30T07:49:18Z")

</div>

Hello.

I want to convert hex data to ascii so I tried several ways on the logstash.config file.  
My reference document is [here](https://stackoverflow.com/questions/61862014/logstash-convert-hex-to-ascii). But it doesn't work for me. There's a error likes 'undefined method pack' .

My source data format example is "0b:33:22:15:32:23:11:15:76:3c" and I changed to "0b33221532231115763c" by using gsub. My problem is how to change hexstring(0b33221532231115763c) to ascii. Is there any idea or way?

Thanks.

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [August 30, 2024, 12:17pm UTC](https://discuss.elastic.co/t/how-to-convert-hex-to-ascii-in-logstash/365803/2 "2024-08-30T12:17:21Z")

</div>

> [@lilyyy](#):
>
> There's a error likes 'undefined method pack' .

The error is probably

```
 undefined method `pack' for "0b33221532231115763c":String

```

which occurs because the String class does not have a .pack method. .pack is a method applicable to the Array class. Thus

```
ruby { code => 'event.set("anotherField", event.get("someField").pack("H*"))' }

```

will get an exception, whereas

```
ruby { code => 'event.set("anotherField", [event.get("someField")].pack("H*"))' }

```

will produce `\v3\"\x152#\x11\x15v<`. That is, vertical tab (0x0b), 3, double quote (0x22) etc.
