# Json codec vs json filter in file input

**URL:** <https://discuss.elastic.co/t/json-codec-vs-json-filter-in-file-input/84976>\
**Category:** Logstash\
**Created:** [May 8, 2017, 8:02pm UTC](https://discuss.elastic.co/t/json-codec-vs-json-filter-in-file-input/84976 "2017-05-08T20:02:07Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![krishna\_chaitanya](https://avatars.discourse-cdn.com/v4/letter/k/b5a626/32.png) [@krishna\_chaitanya](https://discuss.elastic.co/u/krishna_chaitanya)\
**Post date:** [May 8, 2017, 8:02pm UTC](https://discuss.elastic.co/t/json-codec-vs-json-filter-in-file-input/84976/1 "2017-05-08T20:02:07Z")

</div>

I have certain log format:

`<....> [....] - [{...},{...},{...}]`.

With multi line codec and grok patterns, I was able to extract above into `<a> [b] - c`  
Here `c is [{...},{...},{...}]` including the square brackets `[]`

Now, when I tried to parse fields inside json object by applying json filter on `c`, I got a `_jsonparsefailure`. This is my config with json filter:

```
filter {
  json{
     source => c
  }
}

```

But, when my log format is just `[{...},{...},{...}]`, I was able to apply `json codec` and successfully parse the json fields inside it without any failures.

Any suggestion how I can parse json fields inside `<....> [....] - [{...},{...},{...}]` formatted logs ?

---

<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:** [May 8, 2017, 8:28pm UTC](https://discuss.elastic.co/t/json-codec-vs-json-filter-in-file-input/84976/2 "2017-05-08T20:28:04Z")

</div>

Did the Logstash logs contain anything about why it wasn't able to parse the string as JSON?

---

<div class="post-metadata">

**Author:** ![krishna\_chaitanya](https://avatars.discourse-cdn.com/v4/letter/k/b5a626/32.png) [@krishna\_chaitanya](https://discuss.elastic.co/u/krishna_chaitanya)\
**Post date:** [May 9, 2017, 8:05pm UTC](https://discuss.elastic.co/t/json-codec-vs-json-filter-in-file-input/84976/3 "2017-05-09T20:05:24Z")

</div>

Thanks for the reply @magnusbaeck . From the debug logs, it looks like `target` option is necessary for json filter.  
I got this warning message not specifying `target` option.

`Parsed JSON object/hash requires a target configuration option`

But when I specify the target option, I had to rename the fields based on my needs.

---

<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:** [May 10, 2017, 5:37am UTC](https://discuss.elastic.co/t/json-codec-vs-json-filter-in-file-input/84976/4 "2017-05-10T05:37:30Z")

</div>

> From the debug logs, it looks like `target` option is necessary for json filter.

If the parsed string returns a non-object, yes. In your case the JSON string contains an array.

---

<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 7, 2017, 5:49am UTC](https://discuss.elastic.co/t/json-codec-vs-json-filter-in-file-input/84976/5 "2017-06-07T05:49:20Z")

</div>

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