# Retrieving values back from XContentBuilder objects

**URL:** <https://discuss.elastic.co/t/retrieving-values-back-from-xcontentbuilder-objects/13156>\
**Category:** Elasticsearch\
**Created:** [August 9, 2013, 9:25pm UTC](https://discuss.elastic.co/t/retrieving-values-back-from-xcontentbuilder-objects/13156 "2013-08-09T21:25:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jdyck](https://avatars.discourse-cdn.com/v4/letter/j/47e85d/32.png) [@jdyck](https://discuss.elastic.co/u/jdyck)\
**Post date:** [August 9, 2013, 9:25pm UTC](https://discuss.elastic.co/t/retrieving-values-back-from-xcontentbuilder-objects/13156/1 "2013-08-09T21:25:25Z")

</div>

Hey all,

This is kind of a silly question, but I haven't seen this mentioned anywhere and haven't been able to get it working on my own. If I create an XContentBuilder object, is it possible to retrieve values from that object?

Say I have:  
val foo = jsonBuilder().startObject().field("foo", "bar").endObject()

Is it possible to retrieve foo's bar value without having to convert foo to a string and then parsing the JSON again?

Thanks!

---

<div class="post-metadata">

**Author:** ![jprante](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jprante/32/44941_2.png) [@jprante](https://discuss.elastic.co/u/jprante)\
**Post date:** [August 12, 2013, 10:17am UTC](https://discuss.elastic.co/t/retrieving-values-back-from-xcontentbuilder-objects/13156/2 "2013-08-12T10:17:25Z")

</div>

XContentBuilder says it all. It's a builder, not a parser.

In XContentHelper, there is a helper method copyCurrentStructure for  
copying a builder (generator) into a parser, so you can skip the string  
materialization.

Jörg

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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 6, 2017, 2:21am UTC](https://discuss.elastic.co/t/retrieving-values-back-from-xcontentbuilder-objects/13156/3 "2017-07-06T02:21:36Z")

</div>


