# Convert HashMap to Json in Logstash

**URL:** <https://discuss.elastic.co/t/convert-hashmap-to-json-in-logstash/75776>\
**Category:** Logstash\
**Created:** [February 20, 2017, 4:40pm UTC](https://discuss.elastic.co/t/convert-hashmap-to-json-in-logstash/75776 "2017-02-20T16:40:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sachiiit](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sachiiit/32/19163_2.png) [@sachiiit](https://discuss.elastic.co/u/sachiiit)\
**Post date:** [February 20, 2017, 4:40pm UTC](https://discuss.elastic.co/t/convert-hashmap-to-json-in-logstash/75776/1 "2017-02-20T16:40:41Z")

</div>

I am using Logstash in which the input is kafka topic. Through java code we are pushing the HashMap to the topic. According to my requirements, I can't convert the HashMap to json string on my java code side. The example of HashMap is

`[event:[logLevel:INFO, description:This is the test description, className:ClassName, eventType:EVENT_TEST, message:[key1:value1, key2:value2, key3:value3, key4:value4], timestamp:Mon Feb 20 20:36:33 GMT 2017]]`

I want to convert this HashMap to json string in filter block as shown below

```
{"event":{"message":{"key4":"value4","key3":"value3","key2":"value2","key1":"value1"},"timestamp":"Mon Feb 20 18:56:32 IST 2017","logLevel":"INFO","description":"This is the test description","className":"HomePageController","eventType":"EVENT_TEST"}}

```

I am new to Logstash and I am not able to find which input type to use in my logstash config input and what filter to use filter to use or do I need to write my own filter?

---

<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:** [February 22, 2017, 6:39am UTC](https://discuss.elastic.co/t/convert-hashmap-to-json-in-logstash/75776/2 "2017-02-22T06:39:04Z")

</div>

You'd have to write something on your own. The correct solution is of course to change the source application to emit something sensible.

---

<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:** [March 22, 2017, 6:39am UTC](https://discuss.elastic.co/t/convert-hashmap-to-json-in-logstash/75776/3 "2017-03-22T06:39:20Z")

</div>

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