# How to treat JSON as a string

**URL:** <https://discuss.elastic.co/t/how-to-treat-json-as-a-string/170905>\
**Category:** Logstash\
**Created:** [March 5, 2019, 1:08pm UTC](https://discuss.elastic.co/t/how-to-treat-json-as-a-string/170905 "2019-03-05T13:08:58Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![BKG](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bkg/32/43591_2.png) [@BKG](https://discuss.elastic.co/u/BKG)\
**Post date:** [March 5, 2019, 1:08pm UTC](https://discuss.elastic.co/t/how-to-treat-json-as-a-string/170905/1 "2019-03-05T13:08:58Z")

</div>

Hi,

What would be the best way to handle JSON which appears in amongst my normal logs. We don't require parsing of individual fields, just need it to be displayed as a string as this JSON appears very rarely.

As you can see in the message field, it's failing when it's hitting the first JSON element...... or is it a quote escape issue?

I have other multi-line logs working fine.

 ![Screenshot%20from%202019-03-05%2013-04-15](https://us1.discourse-cdn.com/elastic/original/3X/7/7/7768cbfa27abb5956892bf21d32dc98723ba74ce.png)

Thanks!

---

<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:** [March 5, 2019, 1:21pm UTC](https://discuss.elastic.co/t/how-to-treat-json-as-a-string/170905/2 "2019-03-05T13:21:09Z")

</div>

How are you combining the multiple lines into a single event?

---

<div class="post-metadata">

**Author:** ![BKG](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bkg/32/43591_2.png) [@BKG](https://discuss.elastic.co/u/BKG)\
**Post date:** [March 5, 2019, 1:22pm UTC](https://discuss.elastic.co/t/how-to-treat-json-as-a-string/170905/3 "2019-03-05T13:22:36Z")

</div>

Thanks for the reply @Badger

I figured it out.. this is a new type of multi-line log for me.

This is my multiline setup now, which now combines logs that start with " ", "}" or ")"

multiline.pattern: "^( |}|\))"  
multiline.negate: false  
multiline.match: after

---

<div class="post-metadata">

**Author:** ![Wolfram\_Haussig](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wolfram_haussig/32/70528_2.png) [@Wolfram\_Haussig](https://discuss.elastic.co/u/Wolfram_Haussig)\
**Post date:** [March 5, 2019, 1:30pm UTC](https://discuss.elastic.co/t/how-to-treat-json-as-a-string/170905/4 "2019-03-05T13:30:52Z")

</div>

I think you are missing something in your Grok pattern:  
Not working:  
 ![2019-03-05%2014_28_33-Kibana](https://us1.discourse-cdn.com/elastic/original/3X/f/0/f0c92c4c63176a75c732f226201d8962a4dad946.png)  
Working:  
 ![2019-03-05%2014_28_45-Kibana](https://us1.discourse-cdn.com/elastic/original/3X/f/a/fa9583ff39148304627ea02a40968d8b69b2881b.png)  
Note the (?m) at the start telling RegEx to do multiline matching

---

<div class="post-metadata">

**Author:** ![BKG](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bkg/32/43591_2.png) [@BKG](https://discuss.elastic.co/u/BKG)\
**Post date:** [March 5, 2019, 2:19pm UTC](https://discuss.elastic.co/t/how-to-treat-json-as-a-string/170905/5 "2019-03-05T14:19:52Z")

</div>

> [@Wolfram\_Haussig](#):
>
> Note the (?m) at the start telling RegEx to do multiline matching

I had no idea you could do this. It actually seems like a much more resilient way of handling it rather than using multiline.pattern.

Thanks again!

---

<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:** [April 2, 2019, 2:20pm UTC](https://discuss.elastic.co/t/how-to-treat-json-as-a-string/170905/6 "2019-04-02T14:20:01Z")

</div>

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