# How to parse json in grok

**URL:** <https://discuss.elastic.co/t/how-to-parse-json-in-grok/129465>\
**Category:** Logstash\
**Created:** [April 25, 2018, 11:09am UTC](https://discuss.elastic.co/t/how-to-parse-json-in-grok/129465 "2018-04-25T11:09:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jimmy.zhao](https://avatars.discourse-cdn.com/v4/letter/j/91b2a8/32.png) [@jimmy.zhao](https://discuss.elastic.co/u/jimmy.zhao)\
**Post date:** [April 25, 2018, 11:09am UTC](https://discuss.elastic.co/t/how-to-parse-json-in-grok/129465/1 "2018-04-25T11:09:11Z")

</div>

I was trying to parse my Neutron log through grok pattern, the last two fileds are two json string, here is the line.

2018-04-19T05:08:42.833+02:00 localhost neutron-api INFO [type:operate] [pid:2157] [MainThread] [accesslog.py:77 **call**] 172.28.0.24 - - - encode-ZDk3ZDQ0ZmZiODA5MTNiMGMxMzg5OWFj [19/Apr/2018:03:08:42.737146][19/Apr/2018:03:08:42.832755] POST [https://network.az1.dc1.huawei.com/v2.0/ports](https://network.az1.dc1.huawei.com/v2.0/ports) HTTP/1.0 409 191 {"port":{"name":"VM001\_1\_NIC\_1","admin\_state\_up":true,"network\_id":"b358bc9f-6891-4f32-bbe7-4e8e474f95dc","fixed\_ips":[{"subnet\_id":"352faa22-e68c-4d4e-9399-a39310888918","ip\_address":"19.167.210.56"}],"binding:vnic\_type":"normal"}} {"NeutronError": {"message": "Unable to complete operation for network b358bc9f-6891-4f32-bbe7-4e8e474f95dc. The IP address 19.167.210.56 is in use.", "type": "IpAddressInUse", "detail": ""}}

I am using the pattern like this

%{TIMESTAMP\_ISO8601:timestamp}%{SPACE}%{SYSLOGHOST:host}%{SPACE}%{WORD}-%{WORD}%{SPACE}%{LOGLEVEL:level}%{SPACE}(?[.{1,100}])%{SPACE}%{IP:ip}%{SPACE}(?.{1,100}])(?[.{1,100}])%{SPACE}%{WORD:operation}%{SPACE}%{URI:uri}%{SPACE}%{WORD}/%{BASE10NUM}%{SPACE}%{BASE10NUM}%{SPACE}%{BASE10NUM}%{SPACE}(?{"port".{1,1000}}})

How to have two fields that contains the last two json string so that I can pass to json filter?

Really appreciate your help.

---

<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:** [April 25, 2018, 2:04pm UTC](https://discuss.elastic.co/t/how-to-parse-json-in-grok/129465/2 "2018-04-25T14:04:13Z")

</div>

If the first JSON object never contains a space then the following would work. If it can contain a space I cannot think of a way of doing it except for a complicated ruby filter that takes a string containing the the two JSON objects and counts brackets to split them.

```auto
  dissect { mapping => { "message" => '%{timestamp} %{host} %{appname} %{level} [%{}] [pid:%{}] [%{threadname}] %{ip} - - - %{} [%{}][%{}] %{operation} %{uri} %{}/%{} %{} %{} %{json1} %{json2}' } }
  json { source => "json1" target => "first" }
  json { source => "json2" target => "second" }

```

---

<div class="post-metadata">

**Author:** ![jimmy.zhao](https://avatars.discourse-cdn.com/v4/letter/j/91b2a8/32.png) [@jimmy.zhao](https://discuss.elastic.co/u/jimmy.zhao)\
**Post date:** [April 26, 2018, 1:54am UTC](https://discuss.elastic.co/t/how-to-parse-json-in-grok/129465/3 "2018-04-26T01:54:50Z")

</div>

Thank you! It works perfectly in my enviroment!

---

<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:** [May 24, 2018, 1:54am UTC](https://discuss.elastic.co/t/how-to-parse-json-in-grok/129465/4 "2018-05-24T01:54:50Z")

</div>

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