# How to "unicode\_escape" decode a text with painless script?

**URL:** <https://discuss.elastic.co/t/how-to-unicode-escape-decode-a-text-with-painless-script/108792>\
**Category:** Elasticsearch\
**Created:** [November 22, 2017, 9:22pm UTC](https://discuss.elastic.co/t/how-to-unicode-escape-decode-a-text-with-painless-script/108792 "2017-11-22T21:22:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![tumluliu](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tumluliu/32/24580_2.png) [@tumluliu](https://discuss.elastic.co/u/tumluliu)\
**Post date:** [November 22, 2017, 9:22pm UTC](https://discuss.elastic.co/t/how-to-unicode-escape-decode-a-text-with-painless-script/108792/1 "2017-11-22T21:22:43Z")

</div>

I have messages with escaped unicode characters, e.g.

```auto
{\x22hostname\x22:\x22ea55b62367a9\x22,\x22address\x22:\x22172.18.0.4\x22,\x22components\x22:[{\x22name\x22:\x22engine-api\x22,\x22version\x22:\x221.0.9-12\x22},{\x22name\x22:\x22sample\x22,\x22version\x22:\x221.4.2\x22},{\x22name\x22:\x22api-server\x22,\x22version\x22:\x221.2.3-dev207\x22}],\x22database\x22:{\x22createdAt\x22:\x222017-10-27T06:45:09.628\x22,\x22databaseName\x22:\x22generic\x22,\x22dataIdentifier\x22:\x22fO2iOtkd\x22},\x22titlesByLanguage\x22:
{\x22de\x22:\x22Windschutzscheibe\x22,\x22en\x22:\x22Windshield\x22,\x22en_lower\x22:\x22windshield\x22,\x22de_lower\x22:\x22windschutzscheibe\x22}}

```

I am writing a script processor to construct a Ingest node pipeline in ES with Painless. I want to convert such messages to its normal JSON expression. It's pretty trivial in Ruby as I assign such kind of strings to a Ruby string object, it will automatically change to:

```auto
"{\"hostname\":\"ea55b62367a9\",\"address\":\"172.18.0.4\",\"components\":[{\"name\":\"engine-api\",\"version\":\"1.0.9-12\"},{\"name\":\"sample\",\"version\":\"1.4.2\"},{\"name\":\"api-server\",\"version\":\"1.2.3-dev207\"}],\"database\":{\"createdAt\":\"2017-10-27T06:45:09.628\",\"databaseName\":\"generic\",\"dataIdentifier\":\"fO2iOtkd\"},\"titlesByLanguage\":\n{\"de\":\"Windschutzscheibe\",\"en\":\"Windshield\",\"en_lower\":\"windshield\",\"de_lower\":\"windschutzscheibe\"}}"

```

which is fairly easy for the next processors like JSON processor to further filter. But with Painless, how can I do this conversion? It's really painful with painless.

Thanks a lot!

p.s. the version of ES I am using: 6.0.0

---

<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:** [December 20, 2017, 9:23pm UTC](https://discuss.elastic.co/t/how-to-unicode-escape-decode-a-text-with-painless-script/108792/2 "2017-12-20T21:23:13Z")

</div>

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