# Is there any Logstash filter to convert a log-line to json

**URL:** <https://discuss.elastic.co/t/is-there-any-logstash-filter-to-convert-a-log-line-to-json/87922>\
**Category:** Logstash\
**Created:** [June 1, 2017, 2:15pm UTC](https://discuss.elastic.co/t/is-there-any-logstash-filter-to-convert-a-log-line-to-json/87922 "2017-06-01T14:15:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pranav1](https://avatars.discourse-cdn.com/v4/letter/p/f6c823/32.png) [@Pranav1](https://discuss.elastic.co/u/Pranav1)\
**Post date:** [June 1, 2017, 2:15pm UTC](https://discuss.elastic.co/t/is-there-any-logstash-filter-to-convert-a-log-line-to-json/87922/1 "2017-06-01T14:15:08Z")

</div>

I am getting logs having a log line which has key value pair separated by pipe. Example-  
**"apple=1 | banana= 3 | mango=5"**

or

**"apple=1 | banana= 3 | mango=5 | tiger=7 | elephant=1"**

I have to convert this log into a json format using a Logstash filter as follows-

**{**  
**"apple": "1"**  
**"banana": "3"**  
**"banana": "5"**  
**}**  
for first example

and

**{**  
**"apple": "1"**  
**"banana": "3"**  
**"banana": "5"**  
**"tiger": "7"**  
**"elepnat": "1"**  
**}**  
for second example

Note - The number of key value pairs in the log can vary as shown in the above 2 examples.

Is there any filter which can perform the above operation?

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [June 1, 2017, 2:24pm UTC](https://discuss.elastic.co/t/is-there-any-logstash-filter-to-convert-a-log-line-to-json/87922/2 "2017-06-01T14:24:01Z")

</div>

Have a look at the [kv filter](https://www.elastic.co/guide/en/logstash/current/plugins-filters-kv.html).

---

<div class="post-metadata">

**Author:** ![Pranav1](https://avatars.discourse-cdn.com/v4/letter/p/f6c823/32.png) [@Pranav1](https://discuss.elastic.co/u/Pranav1)\
**Post date:** [June 2, 2017, 12:10pm UTC](https://discuss.elastic.co/t/is-there-any-logstash-filter-to-convert-a-log-line-to-json/87922/3 "2017-06-02T12:10:25Z")

</div>

Thanks Christian. It helped.

---

<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:** [June 30, 2017, 12:18pm UTC](https://discuss.elastic.co/t/is-there-any-logstash-filter-to-convert-a-log-line-to-json/87922/4 "2017-06-30T12:18:48Z")

</div>

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