# Logstash filter config to parse JSON

**URL:** https://discuss.elastic.co/t/logstash-filter-config-to-parse-json/53269
**Category:** Logstash
**Created:** [June 20, 2016, 6:14am UTC](https://discuss.elastic.co/t/logstash-filter-config-to-parse-json/53269 "2016-06-20T06:14:47Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![gugansankar](https://avatars.discourse-cdn.com/v4/letter/g/e274bd/32.png) [@gugansankar](https://discuss.elastic.co/u/gugansankar)
#### Post date: [June 20, 2016, 6:14am UTC](https://discuss.elastic.co/t/logstash-filter-config-to-parse-json/53269/1 "2016-06-20T06:14:47Z")

</div>

I tried to parse json input file. But logstash doesn't parse the logs and not adding custom field "add\_field". I think, my filter configuration is wrong. Someone please help me on this.

Logs file:

`{"web1":{"stat1":{"mem":261831,"Name":"stat1","cpu":89}},"web2":{"stat2":{"mem":23456,"Name":"stat2","cpu":76}}`}

Logstash filter config:

```
filter {
    if [type] == "localapp" {
	  if [Name] { 
		date {
				target => "@timestamp"
        	   		locale => "en"
		       	        add_field => { "testapp" => "%{Name}"}
                        } 
		}
	}
 }

```

Output:

```
{
          "web1" => {
        "stat1" => {
             "mem" => 261831,
            "Name" => "stat1",
             "cpu" => 89
        }
    },
          "web2" => {
        "stat2" => {
             "mem" => 23456,
            "Name" => "stat2",
             "cpu" => 76
        }
    },
      "@version" => "1",
    "@timestamp" => "2016-06-20T05:52:25.002Z",
          "type" => "localapp",
          "host" => "gugan"
}

```

Here you can see custom field is not added.

---

<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: [June 20, 2016, 6:21am UTC](https://discuss.elastic.co/t/logstash-filter-config-to-parse-json/53269/2 "2016-06-20T06:21:42Z")

</div>

Your JSON parses just fine.

However, your date filter doesn't contain a `match` option that specifies which field to parse and how it should be parsed. What are you trying to do here?

---

<div class="post-metadata">

### Author: ![gugansankar](https://avatars.discourse-cdn.com/v4/letter/g/e274bd/32.png) [@gugansankar](https://discuss.elastic.co/u/gugansankar)
#### Post date: [June 20, 2016, 6:52am UTC](https://discuss.elastic.co/t/logstash-filter-config-to-parse-json/53269/3 "2016-06-20T06:52:38Z")

</div>

Thanks for your reply.  
I done some correction and adding timestamp into the custom json value.

Log:  
`{"web1":{"Name":"web1","stats":{"mem": 261831,"cpu":89,"timestamp":"2016-06-20 05:32:03"}}}`

Logstash Filter:

```
filter {
    if [type] == "localapp" {
	  if [Name] { 
		date {
				match => ["timestamp", "YYYY-MM-dd HH:mm:ss"]
				target => "@timestamp"
       		   		locale => "en"
		       	        add_field => { "testapp" => "%{Name}"}
                        } 
		}
	}
 }

```

Expecting output:  
1.) Use timestamp value what present on log message .  
2.) Adding custom field for using it to creating separate document type per servers.

Above both conditions are not working . Please help.

---

<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: [June 20, 2016, 7:28am UTC](https://discuss.elastic.co/t/logstash-filter-config-to-parse-json/53269/4 "2016-06-20T07:28:27Z")

</div>

Your fields aren't named `Name` and `timestamp`, they're named `[web1][Name]` and `[web1][stats][timestamp]`.

---

<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: [July 6, 2017, 4:51am UTC](https://discuss.elastic.co/t/logstash-filter-config-to-parse-json/53269/5 "2017-07-06T04:51:55Z")

</div>


