# How to parse json responses in logs

**URL:** <https://discuss.elastic.co/t/how-to-parse-json-responses-in-logs/37754>\
**Category:** Logstash\
**Created:** [December 22, 2015, 12:08pm UTC](https://discuss.elastic.co/t/how-to-parse-json-responses-in-logs/37754 "2015-12-22T12:08:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![clandestino\_bgd](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/clandestino_bgd/32/6487_2.png) [@clandestino\_bgd](https://discuss.elastic.co/u/clandestino_bgd)\
**Post date:** [December 22, 2015, 12:08pm UTC](https://discuss.elastic.co/t/how-to-parse-json-responses-in-logs/37754/1 "2015-12-22T12:08:41Z")

</div>

Hello, could somebody help me figuring this out?  
I have the log file (containing server json responses) in the following format

{"success":true,"data":{"field1":"value1", "field2":"value2"}}  
{"success":true,"data":{"field1":"value11", "field2":"value22"}}  
{"success":false,"data":{"Exception blah blah"}}  
{"success":true,"data":{"field1":"value111", "field2":"value222"}}

and I would like to create a documents in elasticsearch of the type myevent  
with fields: field1 and field2 only if success was true

I had multiple failed attempts with codec =\> json  
json filters, grok patterns, but no luck.

Thank you,  
Milan

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [December 23, 2015, 1:45am UTC](https://discuss.elastic.co/t/how-to-parse-json-responses-in-logs/37754/2 "2015-12-23T01:45:08Z")

</div>

Using `input{ stdin { codec=>json } }` breaks things down correctly.

Then you probably want to do a conditional + grok on the value of the `success` field and from that rebuild the message 🙂

---

<div class="post-metadata">

**Author:** ![clandestino\_bgd](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/clandestino_bgd/32/6487_2.png) [@clandestino\_bgd](https://discuss.elastic.co/u/clandestino_bgd)\
**Post date:** [December 23, 2015, 9:03am UTC](https://discuss.elastic.co/t/how-to-parse-json-responses-in-logs/37754/3 "2015-12-23T09:03:20Z")

</div>

Thanks. Sadly, it doesn't. It stores the whole json under source in ES document.  
I want to store only content of "data" field in the ES source, as explained in the original question.

---

<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, 5:17am UTC](https://discuss.elastic.co/t/how-to-parse-json-responses-in-logs/37754/4 "2017-07-06T05:17:28Z")

</div>


