# Json codec: blank lines make logstash throw errors

**URL:** <https://discuss.elastic.co/t/json-codec-blank-lines-make-logstash-throw-errors/62718>\
**Category:** Logstash\
**Created:** [October 11, 2016, 1:52pm UTC](https://discuss.elastic.co/t/json-codec-blank-lines-make-logstash-throw-errors/62718 "2016-10-11T13:52:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Suny](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/suny/32/22082_2.png) [@Suny](https://discuss.elastic.co/u/Suny)\
**Post date:** [October 11, 2016, 1:52pm UTC](https://discuss.elastic.co/t/json-codec-blank-lines-make-logstash-throw-errors/62718/1 "2016-10-11T13:52:45Z")

</div>

A blank line in a json log makes logstash throw an error:

```
:message=>"JSON codec is expecting array or object/map", :data=>"", :level=>:error

```

since upgrade to logstash 2.3.4  
Is this a bug or a feature?  
I'd prefer if blank lines got ignored.

---

<div class="post-metadata">

**Author:** ![jenko](https://avatars.discourse-cdn.com/v4/letter/j/2acd7d/32.png) [@jenko](https://discuss.elastic.co/u/jenko)\
**Post date:** [October 21, 2016, 4:04pm UTC](https://discuss.elastic.co/t/json-codec-blank-lines-make-logstash-throw-errors/62718/2 "2016-10-21T16:04:18Z")

</div>

I got the same error whether I used the json codec in my input config or in my filter config.

Here's a workaround. It's not pretty, but it works (for me, at least).

```
Don't use the json codec in the file input config.
Use an if/else clause in your filter plugin to drop blank lines. ref: http://stackoverflow.com/questions/28457936/how-can-i-drop-an-empty-line-in-logstash

filter {
    if [message] =~ /^\s*$/ { drop { } }
    else {

        json { source => "message" }

        [the rest of your config]

    }
}

```

The result is no errors, but you will get the annoying "Parsed JSON object/hash requires a target configuration option" warnings.

Hope this helps.

---

<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:** [July 6, 2017, 4:33am UTC](https://discuss.elastic.co/t/json-codec-blank-lines-make-logstash-throw-errors/62718/3 "2017-07-06T04:33:14Z")

</div>

Closed on July 6, 2017, 4:33am UTC


