# How to parse json logs in logstash

**URL:** <https://discuss.elastic.co/t/how-to-parse-json-logs-in-logstash/302358>\
**Category:** Logstash\
**Created:** [April 13, 2022, 3:32pm UTC](https://discuss.elastic.co/t/how-to-parse-json-logs-in-logstash/302358 "2022-04-13T15:32:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![hassnain](https://avatars.discourse-cdn.com/v4/letter/h/76d3ee/32.png) [@hassnain](https://discuss.elastic.co/u/hassnain)\
**Post date:** [April 13, 2022, 3:32pm UTC](https://discuss.elastic.co/t/how-to-parse-json-logs-in-logstash/302358/1 "2022-04-13T15:32:47Z")

</div>

{"className":"HomePageBusiness.java","msisdn":"912345678902","method":"HOMEPAGE","externalAPI":"My project info","message":"Delta this is successfull","timestamp":"2022/04/06 21:49:14","timeElapsed":"0:0:0:109"}

This is a custom generated logs pattern for monitoring API response which is 109 milliseconds in last. I want to show it on kibana, I am really a newbie, can someone help me to convert this unstructured data into structured data. Please guide how to write logstash filter for it.

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [April 13, 2022, 7:02pm UTC](https://discuss.elastic.co/t/how-to-parse-json-logs-in-logstash/302358/2 "2022-04-13T19:02:10Z")

</div>

That is JSON, so you can use a json filter to parse it.

```
json { source => "message" remove_field => ["message"] }

```

To show the response time in kibana it will probably be better to normalize timeElapsed to milliseconds

```
    ruby {
        code => '
            timeElapsed = event.get("timeElapsed")
            if timeElapsed
                timeElapsed = timeElapsed.split(":")
                if timeElapsed.length == 4
                    event.set("timeElapsedMs", timeElapsed[3].to_i + 1000 * timeElapsed[2].to_i + 60000 * timeElapsed[1].to_i + 3600000 * timeElapsed[0].to_i)
                end
            end
        '
    }
```

---

<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:** [May 11, 2022, 7:02pm UTC](https://discuss.elastic.co/t/how-to-parse-json-logs-in-logstash/302358/3 "2022-05-11T19:02:52Z")

</div>

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