# Pass XContentBuilder object to another XContentBuilder

**URL:** <https://discuss.elastic.co/t/pass-xcontentbuilder-object-to-another-xcontentbuilder/50632>\
**Category:** Elasticsearch\
**Created:** [May 21, 2016, 8:21pm UTC](https://discuss.elastic.co/t/pass-xcontentbuilder-object-to-another-xcontentbuilder/50632 "2016-05-21T20:21:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![hansal](https://avatars.discourse-cdn.com/v4/letter/h/2acd7d/32.png) [@hansal](https://discuss.elastic.co/u/hansal)\
**Post date:** [May 21, 2016, 8:21pm UTC](https://discuss.elastic.co/t/pass-xcontentbuilder-object-to-another-xcontentbuilder/50632/1 "2016-05-21T20:21:48Z")

</div>

What I understand from the [docu](https://www.elastic.co/guide/en/elasticsearch/client/java-api/1.6/generate.html) it is possible to use one XContentBuilder for the content of another XContentBuilder.

> You can directly pass numbers, dates and even other XContentBuilder objects.

How to do that?

* * *

What I tried was for example:

```
jsonBuilder().startObject(new XContentBuilderString(CustomInnerXContentBuilder().string())).endObject();

public XContentBuilder CustomInnerXContentBuilder() throws IOException {
    return jsonBuilder().startObject("test").endObject();
}

```

The outcome is quotes are escaped and newlines are "\n" - which is not desired. (Furthermore I added the XContentBuilderString via an additional object, which is also not desired.)  
e.g. outcome:

> ""test"{}" : { }

but I want

> "test"{}

Sidenote: Elasticsearch Java API version 2.2.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:** [July 5, 2017, 10:49pm UTC](https://discuss.elastic.co/t/pass-xcontentbuilder-object-to-another-xcontentbuilder/50632/2 "2017-07-05T22:49:58Z")

</div>


