# How to parse the json string

**URL:** <https://discuss.elastic.co/t/how-to-parse-the-json-string/257768>\
**Category:** Logstash\
**Created:** [December 6, 2020, 9:29am UTC](https://discuss.elastic.co/t/how-to-parse-the-json-string/257768 "2020-12-06T09:29:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![stwang](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stwang/32/115044_2.png) [@stwang](https://discuss.elastic.co/u/stwang)\
**Post date:** [December 6, 2020, 9:29am UTC](https://discuss.elastic.co/t/how-to-parse-the-json-string/257768/1 "2020-12-06T09:29:55Z")

</div>

I have a log file, which the content like below

```auto
{"log":"{\"time\":\"2020-12-02 22:42:00,535\", \"a_key\":\"a_value\"}\n","stream":"stdout","time":"2020-12-02T22:42:05.58702969Z"}

```

I want to parse the log field to json object, how to do that in logstash filter?

---

<div class="post-metadata">

**Author:** ![kelk](https://avatars.discourse-cdn.com/v4/letter/k/13edae/32.png) [@kelk](https://discuss.elastic.co/u/kelk)\
**Post date:** [December 6, 2020, 11:44am UTC](https://discuss.elastic.co/t/how-to-parse-the-json-string/257768/2 "2020-12-06T11:44:27Z")

</div>

> [@stwang](#):
>
> `{"log":"{\"time\":\"2020-12-02 22:42:00,535\", \"a_key\":\"a_value\"}\n","stream":"stdout","time":"2020-12-02T22:42:05.58702969Z"}`

if it is pure json, in the "input" stanza of your logstash, you just need to mention `code=> json` ([json](https://www.elastic.co/guide/en/logstash/current/plugins-codecs-json.html) codec)  
if the original data as "json" in individual lines, then use [json\_lines](https://www.elastic.co/guide/en/logstash/current/plugins-codecs-json_lines.html)

so something like..

```auto
input {
....
     codec => json
...
}

filter { }

output {
.. whatever...
}

```

Or if you want to filter as json, follow the example below

> <https://stackoverflow.com/questions/22941739/using-json-with-logstash>

---

<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:** [January 3, 2021, 11:44am UTC](https://discuss.elastic.co/t/how-to-parse-the-json-string/257768/3 "2021-01-03T11:44:32Z")

</div>

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