简体   繁体   English

logstash json过滤器未解析获取_jsonparsefailure的字段

[英]logstash json filter not parsing fields getting _jsonparsefailure

Hi I am trying to parse a json file. 嗨,我正在尝试解析一个json文件。 I have tried troubleshooting with suggestions from stackoverflow (links at bottom)but none have worked for me. 我已经尝试过使用stackoverflow的建议进行故障排除(底部的链接),但是没有一个对我有用。 I am hoping someone has some insight on probably a silly mistake I am making. 我希望有人对我犯的一个愚蠢的错误有所了解。

I have tried using only the json codec, only the json filter, as well as both. 我试过仅使用json编解码器,仅使用json过滤器以及两者。 For some reason I am still getting this _jsonparsefailure. 由于某种原因,我仍然收到此_jsonparsefailure。 What can I do to get this to work? 我该怎么做才能使它正常工作?

Thanks in advance! 提前致谢!

My json file: 我的json文件:

{
  "log": {
    "version": "1.2",
    "creator": {
      "name": "WebInspector",
      "version": "537.36"
    },
    "pages": [
      {
        "startedDateTime": "2015-10-13T20:28:46.081Z",
        "id": "page_1",
        "title": "https://demo.com",
        "pageTimings": {
          "onContentLoad": 377.8560000064317,
          "onLoad": 377.66200001351535
        }
      },
      {
        "startedDateTime": "2015-10-13T20:29:01.734Z",
        "id": "page_2",
        "title": "https://demo.com",
        "pageTimings": {
          "onContentLoad": 1444.0670000039972,
          "onLoad": 2279.20100002666
        }
      },
      {
        "startedDateTime": "2015-10-13T20:29:04.014Z",
        "id": "page_3",
        "title": "https://demo.com",
        "pageTimings": {
          "onContentLoad": 1802.0240000041667,
          "onLoad": 2242.4060000048485
        }
      },
      {
        "startedDateTime": "2015-10-13T20:29:09.224Z",
        "id": "page_4",
        "title": "https://demo.com",
        "pageTimings": {
          "onContentLoad": 274.82699998654425,
          "onLoad": 1453.034000005573
        }
      }
    ]
  }
}

My logstash conf: 我的logstash conf:

input {
    file {
       type => "json"
       path => "/Users/anonymous/Documents/demo.json"
       start_position => beginning
    }
}

filter{
    json{
        source => "message"
   }
}


output { 
  elasticsearch { host => localhost protocol => "http" port => "9200" } 
  stdout { codec => rubydebug } 
}

Output I am getting from logstash hopefully with clues: 我希望从logstash获得的输出有线索:

Trouble parsing json {:source=>"message", :raw=>"        \"startedDateTime\": \"2015-10-19T18:05:37.887Z\",", :exception=>#<TypeError: can't convert String into Hash>, :level=>:warn}
{
       "message" => "      {",
      "@version" => "1",
    "@timestamp" => "2015-10-26T20:05:53.096Z",
          "host" => "15mbp-09796.local",
          "path" => "/Users/anonymous/Documents/demo.json",
          "type" => "json",
          "tags" => [
        [0] "_jsonparsefailure"
    ]
}

Decompose Logstash json message into fields 将Logstash json消息分解为字段

How to use logstash's json filter? 如何使用Logstash的JSON过滤器?

I test my JSON here JSONLint . 我在这里JSONLint测试我的JSON。 Perhaps this will solve your problem. 也许这可以解决您的问题。 The error I am getting is that it is expecting string. 我得到的错误是它期望字符串。

It seems that you have an unnecessary comma(',') at the end. 看来您最后没有多余的逗号(',')。 Either remove it or add another JSON variable after that. 删除它或在此之后添加另一个JSON变量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM