# Need to convert specific part of message to json in logstash

**URL:** <https://discuss.elastic.co/t/need-to-convert-specific-part-of-message-to-json-in-logstash/92088>\
**Category:** Logstash\
**Created:** [July 6, 2017, 11:24am UTC](https://discuss.elastic.co/t/need-to-convert-specific-part-of-message-to-json-in-logstash/92088 "2017-07-06T11:24:07Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![honey](https://avatars.discourse-cdn.com/v4/letter/h/a4c791/32.png) [@honey](https://discuss.elastic.co/u/honey)\
**Post date:** [July 6, 2017, 11:24am UTC](https://discuss.elastic.co/t/need-to-convert-specific-part-of-message-to-json-in-logstash/92088/1 "2017-07-06T11:24:08Z")

</div>

This is my message filed in logs

{'v':'100001','lj':'f', 'level':'warnining', sys:{'sys':'',v:'',host:''},'tt':'a.db.all',o:{a:{b:{c:100}}}, err:{e:{status:300,message:'someException',stack:'abc prq ' } } }

The output I get after changing it to json in filter and by applying codec =\> json in input is as follows:

parsedMessage.err.e.message someException  
parsedMessage.err.e.stack abc prq  
parsedMessage.err.e.status 300  
parsedMessage.level warnining  
parsedMessage.lj f  
parsedMessage.o.a.b.c 100  
parsedMessage.sys.host   
parsedMessage.sys.sys   
parsedMessage.sys.v   
[parsedMessage.tt](http://parsedMessage.tt) a.db.all  
parsedMessage.v 100001  
pid 27,102  
serverName honey-ThinkPad-L430  
type syslog

But I didn't want to convert "O" to json rather i want to keep it as string.  
Please help me out with this.

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [July 9, 2017, 7:07pm UTC](https://discuss.elastic.co/t/need-to-convert-specific-part-of-message-to-json-in-logstash/92088/2 "2017-07-09T19:07:32Z")

</div>

Use the json\_encode filter to encode the `[parsedMessage][o]` field back to a JSON string.

---

<div class="post-metadata">

**Author:** ![honey](https://avatars.discourse-cdn.com/v4/letter/h/a4c791/32.png) [@honey](https://discuss.elastic.co/u/honey)\
**Post date:** [July 12, 2017, 4:38am UTC](https://discuss.elastic.co/t/need-to-convert-specific-part-of-message-to-json-in-logstash/92088/3 "2017-07-12T04:38:26Z")

</div>

But It shows error in Elasticsearch-6.0.0.

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [July 12, 2017, 10:35am UTC](https://discuss.elastic.co/t/need-to-convert-specific-part-of-message-to-json-in-logstash/92088/4 "2017-07-12T10:35:52Z")

</div>

What Logstash configuration results in an error? What's the error?

_Please_ spend a little more time asking your question so that it's possible to answer.

---

<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 9, 2017, 10:36am UTC](https://discuss.elastic.co/t/need-to-convert-specific-part-of-message-to-json-in-logstash/92088/5 "2017-08-09T10:36:02Z")

</div>

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