# How to parse json fields from a log which have multiple event but without delimiter

**URL:** <https://discuss.elastic.co/t/how-to-parse-json-fields-from-a-log-which-have-multiple-event-but-without-delimiter/191858>\
**Category:** Logstash\
**Created:** [July 23, 2019, 3:38pm UTC](https://discuss.elastic.co/t/how-to-parse-json-fields-from-a-log-which-have-multiple-event-but-without-delimiter/191858 "2019-07-23T15:38:32Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![uma\_rengasamy](https://avatars.discourse-cdn.com/v4/letter/u/e56c9b/32.png) [@uma\_rengasamy](https://discuss.elastic.co/u/uma_rengasamy)\
**Post date:** [July 23, 2019, 3:38pm UTC](https://discuss.elastic.co/t/how-to-parse-json-fields-from-a-log-which-have-multiple-event-but-without-delimiter/191858/1 "2019-07-23T15:38:32Z")

</div>

How to parse json fields from a log which have multiple event but without delimiter?  
The logs are cloudwatch logs streamed to kinesis firehose and stored in s3 which is streamed to logstash

---

<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:** [July 23, 2019, 4:03pm UTC](https://discuss.elastic.co/t/how-to-parse-json-fields-from-a-log-which-have-multiple-event-but-without-delimiter/191858/2 "2019-07-23T16:03:14Z")

</div>

Are you saying you have multiple JSON objects on one event? Like this:

```
{ "foo": 1 } { "bar": 2 }

```

If so, neither a json filter nor a json codec will not parse it correctly. Although interestingly (at least to me) one only parses foo and the other only parses bar!

I think you would have to look at writing a custom parser in ruby.

---

<div class="post-metadata">

**Author:** ![uma\_rengasamy](https://avatars.discourse-cdn.com/v4/letter/u/e56c9b/32.png) [@uma\_rengasamy](https://discuss.elastic.co/u/uma_rengasamy)\
**Post date:** [July 23, 2019, 4:11pm UTC](https://discuss.elastic.co/t/how-to-parse-json-fields-from-a-log-which-have-multiple-event-but-without-delimiter/191858/3 "2019-07-23T16:11:46Z")

</div>

> [@Badger](#):
>
> {

Yes! logs like this

{"key1":"value","key2":"value","key3":["key4":'value","key4":"value"]}{"key1":"value","key2":"value","key3":["key4":'value","key4":"value"]} {"key1":"value","key2":"value","key3":["key4":'value","key4":"value"]}{"key1":"value","key2":"value","key3":["key4":'value","key4":"value"]}

Using Grok can we define entire pattern and define it occurrence

---

<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:** [July 23, 2019, 4:13pm UTC](https://discuss.elastic.co/t/how-to-parse-json-fields-from-a-log-which-have-multiple-event-but-without-delimiter/191858/4 "2019-07-23T16:13:13Z")

</div>

> [@uma\_rengasamy](#):
>
> {"key1":"value","key2":"value","key3":["key4":'value","key4":"value"]}{"key1":"value","key2":"value","key3":["key4":'value","key4":"value"]} {"key1":"value","key2":"value","key3":["key4":'value","key4":"value"]}{"key1":"value","key2":"value","key3":["key4":'value","key4":"value"]}

Is that one event or four? If it is 4 then a json filter or codec will work. If it is one then I do not see an alternative to a custom parser.

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [July 23, 2019, 4:15pm UTC](https://discuss.elastic.co/t/how-to-parse-json-fields-from-a-log-which-have-multiple-event-but-without-delimiter/191858/5 "2019-07-23T16:15:25Z")

</div>

That does not look like valid JSON so a custom parser is probably required.

---

<div class="post-metadata">

**Author:** ![uma\_rengasamy](https://avatars.discourse-cdn.com/v4/letter/u/e56c9b/32.png) [@uma\_rengasamy](https://discuss.elastic.co/u/uma_rengasamy)\
**Post date:** [July 23, 2019, 4:19pm UTC](https://discuss.elastic.co/t/how-to-parse-json-fields-from-a-log-which-have-multiple-event-but-without-delimiter/191858/6 "2019-07-23T16:19:05Z")

</div>

Single Event . Agreed! Will work on custom parser

---

<div class="post-metadata">

**Author:** ![uma\_rengasamy](https://avatars.discourse-cdn.com/v4/letter/u/e56c9b/32.png) [@uma\_rengasamy](https://discuss.elastic.co/u/uma_rengasamy)\
**Post date:** [July 25, 2019, 12:27pm UTC](https://discuss.elastic.co/t/how-to-parse-json-fields-from-a-log-which-have-multiple-event-but-without-delimiter/191858/7 "2019-07-25T12:27:41Z")

</div>

I tried to add new line between json event like below and in o/p section mentioned codec=\>json\_lines . But each json messages are not getting spilled as single event .Any ideas on this?

mutate {  
gsub =\> ["message","}{","}\n{"]  
}  
}

---

<div class="post-metadata">

**Author:** ![uma\_rengasamy](https://avatars.discourse-cdn.com/v4/letter/u/e56c9b/32.png) [@uma\_rengasamy](https://discuss.elastic.co/u/uma_rengasamy)\
**Post date:** [July 26, 2019, 7:36am UTC](https://discuss.elastic.co/t/how-to-parse-json-fields-from-a-log-which-have-multiple-event-but-without-delimiter/191858/8 "2019-07-26T07:36:59Z")

</div>

This worked for me  
mutate {

gsub =\> ["message","}{","}FORSPLITLOGSTASH{"]

}

split{

field =\> message

terminator =\> "FORSPLITLOGSTASH"

}

json{

source =\> message

}

}

Thank you all !

---

<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:** [August 23, 2019, 7:37am UTC](https://discuss.elastic.co/t/how-to-parse-json-fields-from-a-log-which-have-multiple-event-but-without-delimiter/191858/9 "2019-08-23T07:37:00Z")

</div>

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