# Is there a way to expand a String field with quoted JSON into a document

**URL:** <https://discuss.elastic.co/t/is-there-a-way-to-expand-a-string-field-with-quoted-json-into-a-document/14555>\
**Category:** Elasticsearch\
**Created:** [November 22, 2013, 9:29pm UTC](https://discuss.elastic.co/t/is-there-a-way-to-expand-a-string-field-with-quoted-json-into-a-document/14555 "2013-11-22T21:29:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jose\_Malheiro](https://avatars.discourse-cdn.com/v4/letter/j/34f0e0/32.png) [@Jose\_Malheiro](https://discuss.elastic.co/u/Jose_Malheiro)\
**Post date:** [November 22, 2013, 9:29pm UTC](https://discuss.elastic.co/t/is-there-a-way-to-expand-a-string-field-with-quoted-json-into-a-document/14555/1 "2013-11-22T21:29:46Z")

</div>

Hi,

I have a JSON message similar to this:

{  
"methodName": "getDigitalId()",  
"host": "localhost",  
"threadName": "960894892@qtp-699536522-6(355)",  
"requestData": [

"{"data":{"requestContext":{"messageTraceId":null,"senderId":null,"applicationSessionId":null},"userId":"username","uuid":0}}"  
],  
"responseData":  
"{"data":{"requestContext":null,"digitalIdEbo":{"id":935,"username":"blah@some.com","password":"5AED6242E91AEA045306CDA531121FF966DB321F"}}}"  
,  
"eventLocation": "ADAPTOR",  
"applicationSessionId": "dwifj334uhdgfff",  
"applicationVersion": "NOT\_SUPPLIED"  
}

I would like to expand the \*requestData \*and \*responseData \*field as part  
of the document when I insert it into elasticsearch.

Is there a mapping for such type - i.e. expand the quoted JSON string and  
merge it into the JSON document?

The result document should look something like:

{  
"methodName": "getDigitalId()",  
"host": "localhost",  
"threadName": "960894892@qtp-699536522-6(355)",  
"requestData": [  
{  
"data": {  
"requestContext": {  
"messageTraceId": null,  
"senderId": null,  
"applicationSessionId": null  
},  
"userId": "username",  
"uuid": 0  
}  
}  
],  
"responseData": {  
"data": {  
"requestContext": null,  
"digitalIdEbo": {  
"id": 935,  
"username": "blah@some.com",  
"password": "5AED6242E91AEA045306CDA531121FF966DB321F"  
}  
}  
},  
"eventLocation": "ADAPTOR",  
"applicationSessionId": "dwifj334uhdgfff",  
"applicationVersion": "NOT\_SUPPLIED"  
}

thanking you in advance.

--  
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:** ![ppearcy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ppearcy/32/980_2.png) [@ppearcy](https://discuss.elastic.co/u/ppearcy)\
**Post date:** [November 25, 2013, 7:55pm UTC](https://discuss.elastic.co/t/is-there-a-way-to-expand-a-string-field-with-quoted-json-into-a-document/14555/2 "2013-11-25T19:55:13Z")

</div>

Nothing I know of like this exists, but should be easy to do if you are  
working in Java with the Jackson API. I'd think any other  
framework/language you are working in would have similar facilities to  
parse JSON.

Best Regards,  
Paul

On Friday, November 22, 2013 4:29:46 PM UTC-5, Jose Malheiro wrote:

> Hi,
> 
> I have a JSON message similar to this:
> 
> {  
> "methodName": "getDigitalId()",  
> "host": "localhost",  
> "threadName": "960894892@qtp-699536522-6(355)",  
> "requestData": [
> 
> "{"data":{"requestContext":{"messageTraceId":null,"senderId":null,"applicationSessionId":null},"userId":"username","uuid":0}}"  
> ],  
> "responseData":  
> "{"data":{"requestContext":null,"digitalIdEbo":{"id":935,"username":"  
> [bl...@some.com](mailto:bl...@some.com) \<javascript:\>  
> ","password":"5AED6242E91AEA045306CDA531121FF966DB321F"}}}",  
> "eventLocation": "ADAPTOR",  
> "applicationSessionId": "dwifj334uhdgfff",  
> "applicationVersion": "NOT\_SUPPLIED"  
> }
> 
> I would like to expand the \*requestData \*and \*responseData \*field as part  
> of the document when I insert it into elasticsearch.
> 
> Is there a mapping for such type - i.e. expand the quoted JSON string and  
> merge it into the JSON document?
> 
> The result document should look something like:
> 
> {  
> "methodName": "getDigitalId()",  
> "host": "localhost",  
> "threadName": "960894892@qtp-699536522-6(355)",  
> "requestData": [  
> {  
> "data": {  
> "requestContext": {  
> "messageTraceId": null,  
> "senderId": null,  
> "applicationSessionId": null  
> },  
> "userId": "username",  
> "uuid": 0  
> }  
> }  
> ],  
> "responseData": {  
> "data": {  
> "requestContext": null,  
> "digitalIdEbo": {  
> "id": 935,  
> "username": "[bl...@some.com](mailto:bl...@some.com) \<javascript:\>",  
> "password": "5AED6242E91AEA045306CDA531121FF966DB321F"  
> }  
> }  
> },  
> "eventLocation": "ADAPTOR",  
> "applicationSessionId": "dwifj334uhdgfff",  
> "applicationVersion": "NOT\_SUPPLIED"  
> }
> 
> thanking you in advance.

--  
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:** ![Jose\_Malheiro](https://avatars.discourse-cdn.com/v4/letter/j/34f0e0/32.png) [@Jose\_Malheiro](https://discuss.elastic.co/u/Jose_Malheiro)\
**Post date:** [November 30, 2013, 3:40pm UTC](https://discuss.elastic.co/t/is-there-a-way-to-expand-a-string-field-with-quoted-json-into-a-document/14555/3 "2013-11-30T15:40:04Z")

</div>

Thanks Paul, but unfortunately I don't have access to the source message -  
would've been great to have a mapping that would 'automagically' do this  
when adding a document.

What I may have to do is parse the JSON first and then convert the String  
to JSON for those fields.

cheers, Jose.

On Monday, 25 November 2013 21:55:13 UTC+2, ppearcy wrote:

> Nothing I know of like this exists, but should be easy to do if you are  
> working in Java with the Jackson API. I'd think any other  
> framework/language you are working in would have similar facilities to  
> parse JSON.
> 
> Best Regards,  
> Paul
> 
> On Friday, November 22, 2013 4:29:46 PM UTC-5, Jose Malheiro wrote:
> 
> > Hi,
> > 
> > I have a JSON message similar to this:
> > 
> > {  
> > "methodName": "getDigitalId()",  
> > "host": "localhost",  
> > "threadName": "960894892@qtp-699536522-6(355)",  
> > "requestData": [
> > 
> > "{"data":{"requestContext":{"messageTraceId":null,"senderId":null,"applicationSessionId":null},"userId":"username","uuid":0}}"  
> > ],  
> > "responseData":  
> > "{"data":{"requestContext":null,"digitalIdEbo":{"id":935,"username":"  
> > [bl...@some.com](mailto:bl...@some.com)  
> > ","password":"5AED6242E91AEA045306CDA531121FF966DB321F"}}}",  
> > "eventLocation": "ADAPTOR",  
> > "applicationSessionId": "dwifj334uhdgfff",  
> > "applicationVersion": "NOT\_SUPPLIED"  
> > }
> > 
> > I would like to expand the \*requestData \*and \*responseData \*field as  
> > part of the document when I insert it into elasticsearch.
> > 
> > Is there a mapping for such type - i.e. expand the quoted JSON string and  
> > merge it into the JSON document?
> > 
> > The result document should look something like:
> > 
> > {  
> > "methodName": "getDigitalId()",  
> > "host": "localhost",  
> > "threadName": "960894892@qtp-699536522-6(355)",  
> > "requestData": [  
> > {  
> > "data": {  
> > "requestContext": {  
> > "messageTraceId": null,  
> > "senderId": null,  
> > "applicationSessionId": null  
> > },  
> > "userId": "username",  
> > "uuid": 0  
> > }  
> > }  
> > ],  
> > "responseData": {  
> > "data": {  
> > "requestContext": null,  
> > "digitalIdEbo": {  
> > "id": 935,  
> > "username": "[bl...@some.com](mailto:bl...@some.com)",  
> > "password": "5AED6242E91AEA045306CDA531121FF966DB321F"  
> > }  
> > }  
> > },  
> > "eventLocation": "ADAPTOR",  
> > "applicationSessionId": "dwifj334uhdgfff",  
> > "applicationVersion": "NOT\_SUPPLIED"  
> > }
> > 
> > thanking you in advance.

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/2693e81c-252e-42bb-81d3-6cad639e6918%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/2693e81c-252e-42bb-81d3-6cad639e6918%40googlegroups.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:04am UTC](https://discuss.elastic.co/t/is-there-a-way-to-expand-a-string-field-with-quoted-json-into-a-document/14555/4 "2017-07-06T02:04:05Z")

</div>


