# How to make nested JSON a string with escaped quotes?

**URL:** <https://discuss.elastic.co/t/how-to-make-nested-json-a-string-with-escaped-quotes/189138>\
**Category:** Elasticsearch\
**Tags:** painless\
**Created:** [July 5, 2019, 4:00pm UTC](https://discuss.elastic.co/t/how-to-make-nested-json-a-string-with-escaped-quotes/189138 "2019-07-05T16:00:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![samuelburnett](https://avatars.discourse-cdn.com/v4/letter/s/bbce88/32.png) [@samuelburnett](https://discuss.elastic.co/u/samuelburnett)\
**Post date:** [July 5, 2019, 4:00pm UTC](https://discuss.elastic.co/t/how-to-make-nested-json-a-string-with-escaped-quotes/189138/1 "2019-07-05T16:00:08Z")

</div>

I am making a Watch that outputs something like this:

> {  
> "nonIdentifyingInfo": {"loginAttempts": 2},  
> "identifyingInfo":{"domain": "domain\_01", "userName": "john\_doe"},  
> "baseAlertId": 1  
> }

However, I need the nested JSON to be a string with escaped quotes like this:

> {  
> "nonIdentifyingInfo": "{"loginAttempts": "1"}",  
> "identifyingInfo": "{"userName": "john\_doe", "domain": "domain\_01"}",  
> "baseAlertId": 1  
> }

My current workaround is a painless script that makes the above output, but I was looking for a more dynamic solution. Any ideas?

---

<div class="post-metadata">

**Author:** ![samuelburnett](https://avatars.discourse-cdn.com/v4/letter/s/bbce88/32.png) [@samuelburnett](https://discuss.elastic.co/u/samuelburnett)\
**Post date:** [July 5, 2019, 6:53pm UTC](https://discuss.elastic.co/t/how-to-make-nested-json-a-string-with-escaped-quotes/189138/2 "2019-07-05T18:53:00Z")

</div>

I'm not sure if I forgot to escape the inner quotes or they were just automatically removed, but the inner quotes are supposed to be escaped.

---

<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:** [August 2, 2019, 6:53pm UTC](https://discuss.elastic.co/t/how-to-make-nested-json-a-string-with-escaped-quotes/189138/3 "2019-08-02T18:53:01Z")

</div>

Closed on August 2, 2019, 6:53pm UTC

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