# Grok everything until a character and include that character in a field

**URL:** <https://discuss.elastic.co/t/grok-everything-until-a-character-and-include-that-character-in-a-field/122122>\
**Category:** Logstash\
**Created:** [March 1, 2018, 4:46pm UTC](https://discuss.elastic.co/t/grok-everything-until-a-character-and-include-that-character-in-a-field/122122 "2018-03-01T16:46:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pdna](https://avatars.discourse-cdn.com/v4/letter/p/3bc359/32.png) [@pdna](https://discuss.elastic.co/u/pdna)\
**Post date:** [March 1, 2018, 4:46pm UTC](https://discuss.elastic.co/t/grok-everything-until-a-character-and-include-that-character-in-a-field/122122/1 "2018-03-01T16:46:11Z")

</div>

`{"level":"error","message":"Token Generation Failed {\"error\":{}}","timestamp":"2017-11-15T17:58:00.402Z"}`  
In the message field, I want to extract everything until { character as message\_type and store everything starting { as message including {. I'd appreciate any suggestions.

Note: I have set `config.support_escapes: true` in my logstash.yml to parse JSON.

```auto
filter {
#the following json filter would extract the fields level, message and timestamp
  json {
    source => "message"
  }
#I want to extract everything until { character as message_type and store everything starting { as message including {. I wonder if I have to add a double quote before this { 
  grok {
    match => { "message" => ["(%{DATA:message_type})?{{DATA:message}"] }
  }
#further parsing of json message
  json {
    source => "message"
  }
}

```

The following log is grokked successfully by the filter since it doesn't have a message type in it  
`{"level":"debug","message":"{\"code\":\"Access-Request\",\"identifier\":0,\"attributes\":[[\"User-Name\",\"ab@example.com\"]]}","timestamp":"2017-11-15T17:58:02.793Z"}`

---

<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:** [March 1, 2018, 8:02pm UTC](https://discuss.elastic.co/t/grok-everything-until-a-character-and-include-that-character-in-a-field/122122/2 "2018-03-01T20:02:37Z")

</div>

`[^{]*` matches zero or more characters of any kind _except_ `{`. (You might have to escape the closing brace with a backslash.)

---

<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:** [March 29, 2018, 8:02pm UTC](https://discuss.elastic.co/t/grok-everything-until-a-character-and-include-that-character-in-a-field/122122/3 "2018-03-29T20:02:55Z")

</div>

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