# File input JSON with multiline codec plugin

**URL:** https://discuss.elastic.co/t/file-input-json-with-multiline-codec-plugin/204669
**Category:** Logstash
**Created:** [October 22, 2019, 2:29pm UTC](https://discuss.elastic.co/t/file-input-json-with-multiline-codec-plugin/204669 "2019-10-22T14:29:27Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Krypton8](https://avatars.discourse-cdn.com/v4/letter/k/f05b48/32.png) [@Krypton8](https://discuss.elastic.co/u/Krypton8)
#### Post date: [October 22, 2019, 2:29pm UTC](https://discuss.elastic.co/t/file-input-json-with-multiline-codec-plugin/204669/1 "2019-10-22T14:29:27Z")

</div>

Hello,

I'm simply trying to parse my JSON fileds into events.

The JSON file look like this:

> [  
> {  
> "field1": "value1",  
> "field2": "value2",  
> "field3": "value3",  
> "field4": "value4",  
> "field5": "value5",  
> "field6": "value6"  
> },  
> {  
> "field1": "value1",  
> "field2": "value2",  
> "field3": "value3",  
> "field4": "value4",  
> "field5": "value5",  
> "field6": "value6"  
> }  
> ]

I would like to parse it to have one event of the 6 fields, with their value.

So I did some research and find that I have to use the Multiline codec plugin with the pattern option. I tried a lot of pattern but I have a parse error everytime.

> [WARN][logstash.filters.json] Error parsing json {:source=\>"message", :raw=\>" },\r", :exception=\>#\<LogStash::Json::ParserError:"; line: 1, column: 0])r '}': expected ']' (for root starting at [Source: (byte)" },

My input look like this:

> input {  
> file {  
> codec =\> multiline {  
> pattern =\> "^\s\s\s\s"  
> negate =\> true  
> what =\> previous  
> max\_lines =\> 20000  
> }  
> path =\> "/etc/logstash/conf.d/adcsi/MyJson.json"  
> type =\> "json"  
> sincedb\_path =\> "/dev/null"  
> start\_position =\> "beginning"  
> }

My filter:

> filter {  
> if [type] == "json" {  
> json {  
> source =\> "message"  
> }  
> }  
> }

Any help would be appreciate !

---

<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: [October 22, 2019, 3:08pm UTC](https://discuss.elastic.co/t/file-input-json-with-multiline-codec-plugin/204669/2 "2019-10-22T15:08:34Z")

</div>

Take a look at [this](https://discuss.elastic.co/t/parsing-array-of-json-objects-with-logstash-and-injesting-to-elastic/203197/2).

---

<div class="post-metadata">

### Author: ![Krypton8](https://avatars.discourse-cdn.com/v4/letter/k/f05b48/32.png) [@Krypton8](https://discuss.elastic.co/u/Krypton8)
#### Post date: [October 23, 2019, 9:40am UTC](https://discuss.elastic.co/t/file-input-json-with-multiline-codec-plugin/204669/3 "2019-10-23T09:40:50Z")

</div>

Thank you for your response, I will try this today and inform you if it worked !

Have a great day

---

<div class="post-metadata">

### Author: ![Krypton8](https://avatars.discourse-cdn.com/v4/letter/k/f05b48/32.png) [@Krypton8](https://discuss.elastic.co/u/Krypton8)
#### Post date: [October 28, 2019, 10:28am UTC](https://discuss.elastic.co/t/file-input-json-with-multiline-codec-plugin/204669/4 "2019-10-28T10:28:55Z")

</div>

Hello Badger,

Your solution doesn't seem to work.

Here is the error I get :

> [WARN][logstash.filters.split] Only String and Array types are splittable. field:someField is of type = NilClass

Here is my input:

> ```
> file {
> codec => multiline { 
> pattern => "^Spalanzani" 
> negate => true 
> what => previous 
> auto_flush_interval => 1 
> multiline_tag => "" 
> }
> path => "/etc/logstash/conf.d/adcsi/Users.json"
> type => "adcsi-users"
> sincedb_path => "/dev/null"
> start_position => "beginning"
> }
> 
> ```

Here is my filter for this json:

> filter {  
> if [type] == "adcsi-users"{  
> json {  
> source =\> "message"  
> target =\> "someField"  
> remove\_field =\> ["message"]  
> }  
> split {  
> field =\> "someField"  
> }  
> }  
> }

Do I need to change the format of my Json to make a JSON Lines ? Where every line is an object ? If so, I have 2000+ lines to change, is there any other solution that doesn't need to reformat my json ?

Thank you for your help.

Best regards

---

<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: [October 28, 2019, 12:29pm UTC](https://discuss.elastic.co/t/file-input-json-with-multiline-codec-plugin/204669/5 "2019-10-28T12:29:25Z")

</div>

That is telling you that [someField] does not exist, which means your json filter did not parse [message].

---

<div class="post-metadata">

### Author: ![Krypton8](https://avatars.discourse-cdn.com/v4/letter/k/f05b48/32.png) [@Krypton8](https://discuss.elastic.co/u/Krypton8)
#### Post date: [October 28, 2019, 12:40pm UTC](https://discuss.elastic.co/t/file-input-json-with-multiline-codec-plugin/204669/6 "2019-10-28T12:40:35Z")

</div>

Yes... That's the problem...

It did not solve my problem, I really don't understand what I have to do to parse my json correctly...

---

<div class="post-metadata">

### Author: ![Krypton8](https://avatars.discourse-cdn.com/v4/letter/k/f05b48/32.png) [@Krypton8](https://discuss.elastic.co/u/Krypton8)
#### Post date: [November 5, 2019, 9:38am UTC](https://discuss.elastic.co/t/file-input-json-with-multiline-codec-plugin/204669/7 "2019-11-05T09:38:07Z")

</div>

I haven't find a solution for my Json.

My solution was to convert my JSON into a CSV file. Now works properly...

---

<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: [December 3, 2019, 9:38am UTC](https://discuss.elastic.co/t/file-input-json-with-multiline-codec-plugin/204669/8 "2019-12-03T09:38:10Z")

</div>

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