# Invalid JSON PARSE FAILURE DUE TO LEADING ZEROS

**URL:** https://discuss.elastic.co/t/invalid-json-parse-failure-due-to-leading-zeros/201736
**Category:** Logstash
**Created:** [October 1, 2019, 6:58am UTC](https://discuss.elastic.co/t/invalid-json-parse-failure-due-to-leading-zeros/201736 "2019-10-01T06:58:52Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![ashish\_kumar1490](https://avatars.discourse-cdn.com/v4/letter/a/a4c791/32.png) [@ashish\_kumar1490](https://discuss.elastic.co/u/ashish_kumar1490)
#### Post date: [October 1, 2019, 6:58am UTC](https://discuss.elastic.co/t/invalid-json-parse-failure-due-to-leading-zeros/201736/1 "2019-10-01T06:58:52Z")

</div>

I am getting the above exception when I parsing log -

{"ProcessName":"c:/windows/system32/svchost.exe","cpuPerc":0,"cpuTime":"00:00","memResident":1237319680,"memSize":1090519040,"pid":660,"startTime":1569254748000,"state":"Running","user":""}

for cpuTime. Please suggest me a way.

---

<div class="post-metadata">

### Author: ![ashish\_kumar1490](https://avatars.discourse-cdn.com/v4/letter/a/a4c791/32.png) [@ashish\_kumar1490](https://discuss.elastic.co/u/ashish_kumar1490)
#### Post date: [October 1, 2019, 8:39am UTC](https://discuss.elastic.co/t/invalid-json-parse-failure-due-to-leading-zeros/201736/2 "2019-10-01T08:39:23Z")

</div>

Please could anyone suggest. Please help me in this.

---

<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: [October 1, 2019, 12:48pm UTC](https://discuss.elastic.co/t/invalid-json-parse-failure-due-to-leading-zeros/201736/3 "2019-10-01T12:48:49Z")

</div>

A json filter has no problem parsing the JSON that you show. It would log that error if, for example, the cpuPerc field were

```
"cpuPerc":01

```

because JSON does not permit leading zeros on a numeric value. cpuTime is a string, not numeric, so it does not apply there.

You may be able to convert your events to valid JSON using a mutate filter.

---

<div class="post-metadata">

### Author: ![ashish\_kumar1490](https://avatars.discourse-cdn.com/v4/letter/a/a4c791/32.png) [@ashish\_kumar1490](https://discuss.elastic.co/u/ashish_kumar1490)
#### Post date: [October 3, 2019, 3:53am UTC](https://discuss.elastic.co/t/invalid-json-parse-failure-due-to-leading-zeros/201736/4 "2019-10-03T03:53:14Z")

</div>

okay, but the Invalid JSON Failure is given on **cpuTime** though it is already String and I check the JSON is valid.

Please suggest how I remove this exception of 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: [October 3, 2019, 1:35pm UTC](https://discuss.elastic.co/t/invalid-json-parse-failure-due-to-leading-zeros/201736/5 "2019-10-03T13:35:20Z")

</div>

I am unable to reproduce the problem. Perhaps upgrading to a current version would fix it.

---

<div class="post-metadata">

### Author: ![ashish\_kumar1490](https://avatars.discourse-cdn.com/v4/letter/a/a4c791/32.png) [@ashish\_kumar1490](https://discuss.elastic.co/u/ashish_kumar1490)
#### Post date: [October 4, 2019, 5:08am UTC](https://discuss.elastic.co/t/invalid-json-parse-failure-due-to-leading-zeros/201736/6 "2019-10-04T05:08:35Z")

</div>

My Conf file is -

input {  
tcp {  
port =\> 12345  
codec =\>json  
}  
}  
filter {  
json {  
source =\> "message"  
}  
}  
output  
{  
stdout { codec =\> json }  
elasticsearch  
{  
hosts =\> ["localhost:9200"]  
index =\> "kumar-%{+YYYY.MM.dd}"  
}  
}

---

<div class="post-metadata">

### Author: ![ashish\_kumar1490](https://avatars.discourse-cdn.com/v4/letter/a/a4c791/32.png) [@ashish\_kumar1490](https://discuss.elastic.co/u/ashish_kumar1490)
#### Post date: [October 4, 2019, 5:10am UTC](https://discuss.elastic.co/t/invalid-json-parse-failure-due-to-leading-zeros/201736/7 "2019-10-04T05:10:28Z")

</div>

JSON to be parsed -

```
{
	"MessageType": "query",
	"ProcessInfo": null,
	"antivirusdetail": null,
	"arch": "10.0.17134",
	"basicResponse": "yes#1570165120032#Windows#Microsoft Windows 10 Enterprise#10.11.92.0#Desktop#Member Workstation#####All Devices#",
	"cpudetail": {
		"com.accelerite.radialive.common.messageresponse.avro.CPUInfo": {
			"ProcessDetailsList": [{
				"ProcessName": "",
				"cpuPerc": 100,
				"cpuTime": "5019:09",
				"memResident": 8388608,
				"memSize": 54525952,
				"pid": 0,
				"startTime": 1569920676000,
				"state": "Running",
				"user": ""
			}, {
				"ProcessName": "",
				"cpuPerc": 21,
				"cpuTime": "100:58",
				"memResident": 1962934272,
				"memSize": 197132288,
				"pid": 4,
				"startTime": 1569920676000,
				"state": "Running",
				"user": ""
			}, {
				"ProcessName": "",
				"cpuPerc": 0,
				"cpuTime": "00:07",
				"memResident": 15888023552,
				"memSize": 2671771648,
				"pid": 96,
				"startTime": 1569920670000,
				"state": "Running",
				"user": ""
			}, {
				"ProcessName": "c:/windows/system32/svchost.exe",
				"cpuPerc": 0,
				"cpuTime": "00:00",
				"memResident": 985661440,
				"memSize": 1090519040,
				"pid": 344,
				"startTime": 1569920693000,
				"state": "Running",
				"user": ""
			}, {
				"ProcessName": "C:/Windows/SystemApps/Microsoft.LockApp_cw5n1h2txyewy/LockApp.exe",
				"cpuPerc": 0,
				"cpuTime": "00:04",
				"memResident": 32111591424,
				"memSize": 18744344576,
				"pid": 352,
				"startTime": 1569925596000,
				"state": "Running",
				"user": ""
			}, {
				"ProcessName": "",
				"cpuPerc": 0,
				"cpuTime": "00:00",
				"memResident": 255852544,
				"memSize": 515899392,
				"pid": 524,
				"startTime": 1569920676000,
				"state": "Running",
				"user": ""
			}, {
				"ProcessName": "C:/WINDOWS/system32/svchost.exe",
				"cpuPerc": 0,
				"cpuTime": "00:59",
				"memResident": 19310575616,
				"memSize": 15883829248,
				"pid": 608,
				"startTime": 1569920693000,
				"state": "Running",
				"user": ""
			}]
		}
	}
}
```

---

<div class="post-metadata">

### Author: ![ashish\_kumar1490](https://avatars.discourse-cdn.com/v4/letter/a/a4c791/32.png) [@ashish\_kumar1490](https://discuss.elastic.co/u/ashish_kumar1490)
#### Post date: [October 4, 2019, 5:11am UTC](https://discuss.elastic.co/t/invalid-json-parse-failure-due-to-leading-zeros/201736/8 "2019-10-04T05:11:14Z")

</div>

and the ERROR on console -

[2019-10-04T10:32:06,196][ERROR][logstash.codecs.json][main] JSON parse error, original data now in message field {:error=\>#\<LogStash::Json::ParserError: Unexpected end-of-input: was expecting closing quote for a string value at [Source: (String)"{"MessageType":"query","ProcessInfo":null,"antivirusdetail":null,"arch":"10.0.17134","basicResponse":"yes#1570165323292#Windows#Microsoft Windows 10 Enterprise#10.11.92.0#Desktop#Member Workstation#####All Devices#","cpudetail":{"com.accelerite.radialive.common.messageresponse.avro.CPUInfo":{"ProcessDetailsList":[{"ProcessName":"","cpuPerc":92,"cpuTime":"5024:43","memResident":8388608,"memSize":54525952,"pid":0,"startTime":1569920676000,"state":"Running","user":""},{"ProcessName":"","cpuPerc":17"[truncated 524 chars]; line: 1, column: 2049]\>, :data=\>"{"MessageType":"query","ProcessInfo":null,"antivirusdetail":null,"arch":"10.0.17134","basicResponse":"yes#1570165323292#Windows#Microsoft Windows 10 Enterprise#10.11.92.0#Desktop#Member Workstation#####All Devices#","cpudetail":{"com.accelerite.radialive.common.messageresponse.avro.CPUInfo":{"ProcessDetailsList":[{"ProcessName":"","cpuPerc":92,"cpuTime":"5024:43","memResident":8388608,"memSize":54525952,"pid":0,"startTime":1569920676000,"state":"Running","user":""},{"ProcessName":"","cpuPerc":17,"cpuTime":"101:17","memResident":1962934272,"memSize":197132288,"pid":4,"startTime":1569920676000,"state":"Running","user":""},{"ProcessName":"","cpuPerc":0,"cpuTime":"00:07","memResident":15908995072,"memSize":2646605824,"pid":96,"startTime":1569920670000,"state":"Running","user":""},{"ProcessName":"c:/windows/system32/svchost.exe","cpuPerc":0,"cpuTime":"00:00","memResident":981467136,"memSize":1090519040,"pid":344,"startTime":1569920693000,"state":"Running","user":""},{"ProcessName":"C:/Windows/SystemApps/Microsoft."} [2019-10-04T10:32:06,234][ERROR][logstash.codecs.json][main] JSON parse error, original data now in message field {:error=\>#\<LogStash::Json::ParserError: Unrecognized token 'LockApp\_cw5n1h2txyewy': was expecting ('true', 'false' or 'null') at [Source: (String)"LockApp\_cw5n1h2txyewy/LockApp.exe","cpuPerc":0,"cpuTime":"00:04","memResident":32111591424,"memSize":18744344576,"pid":352,"startTime":1569925596000,"state":"Running","user":""}

JSON is VALID

---

<div class="post-metadata">

### Author: ![ashish\_kumar1490](https://avatars.discourse-cdn.com/v4/letter/a/a4c791/32.png) [@ashish\_kumar1490](https://discuss.elastic.co/u/ashish_kumar1490)
#### Post date: [October 4, 2019, 6:15am UTC](https://discuss.elastic.co/t/invalid-json-parse-failure-due-to-leading-zeros/201736/9 "2019-10-04T06:15:25Z")

</div>

When I copy this JSON to file in desktop then parsing is working correctly. Not getting exactly what is happening

---

<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: [October 4, 2019, 1:21pm UTC](https://discuss.elastic.co/t/invalid-json-parse-failure-due-to-leading-zeros/201736/10 "2019-10-04T13:21:06Z")

</div>

A tcp input accepts lines of text. My guess is that something is inserting a newline into your JSON in the middle of

```
"ProcessName": "C:/Windows/SystemApps/Microsoft.
LockApp_cw5n1h2txyewy/LockApp.exe",
```

---

<div class="post-metadata">

### Author: ![ashish\_kumar1490](https://avatars.discourse-cdn.com/v4/letter/a/a4c791/32.png) [@ashish\_kumar1490](https://discuss.elastic.co/u/ashish_kumar1490)
#### Post date: [October 7, 2019, 10:29am UTC](https://discuss.elastic.co/t/invalid-json-parse-failure-due-to-leading-zeros/201736/11 "2019-10-07T10:29:39Z")

</div>

I have check the JSON is coming in valid problem in my codec of Logstash.

I changed that codec from "json" to "json\_lines" and parsing is working fine.

---

<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: [November 4, 2019, 10:30am UTC](https://discuss.elastic.co/t/invalid-json-parse-failure-due-to-leading-zeros/201736/12 "2019-11-04T10:30:04Z")

</div>

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