# How convert Hashmap to JSON string in painless script?

**URL:** <https://discuss.elastic.co/t/how-convert-hashmap-to-json-string-in-painless-script/107994>\
**Category:** Elasticsearch\
**Created:** [November 16, 2017, 5:59pm UTC](https://discuss.elastic.co/t/how-convert-hashmap-to-json-string-in-painless-script/107994 "2017-11-16T17:59:02Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![RomainXie](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/romainxie/32/22427_2.png) [@RomainXie](https://discuss.elastic.co/u/RomainXie)\
**Post date:** [November 16, 2017, 5:59pm UTC](https://discuss.elastic.co/t/how-convert-hashmap-to-json-string-in-painless-script/107994/1 "2017-11-16T17:59:03Z")

</div>

Hi,

I want to convert a hashmap to a json object or a json string in the painless script.  
I know I can use the {{#tojson}} to convert it in the mustache. But I need add slash before each double-quote in the output.  
Is there any way can do it?

Thanks a lot.

---

<div class="post-metadata">

**Author:** ![rjernst](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rjernst/32/6363_2.png) [@rjernst](https://discuss.elastic.co/u/rjernst)\
**Post date:** [November 16, 2017, 8:47pm UTC](https://discuss.elastic.co/t/how-convert-hashmap-to-json-string-in-painless-script/107994/2 "2017-11-16T20:47:08Z")

</div>

At this time there is no helper method for this in painless. It will likely come in a future release (hoping for some time in 6.x).

---

<div class="post-metadata">

**Author:** ![RomainXie](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/romainxie/32/22427_2.png) [@RomainXie](https://discuss.elastic.co/u/RomainXie)\
**Post date:** [November 17, 2017, 5:28am UTC](https://discuss.elastic.co/t/how-convert-hashmap-to-json-string-in-painless-script/107994/3 "2017-11-17T05:28:26Z")

</div>

Hi, @rjernst

Thank you, I hope too.  
I try to concatenate the items' string 😢

---

<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 15, 2017, 5:28am UTC](https://discuss.elastic.co/t/how-convert-hashmap-to-json-string-in-painless-script/107994/4 "2017-12-15T05:28:56Z")

</div>

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