【问题标题】:logstash json filter not parsing fields getting _jsonparsefailurelogstash json过滤器不解析字段获取_jsonparsefailure
【发布时间】:2016-01-27 00:40:48
【问题描述】:

您好,我正在尝试解析 json 文件。我已经尝试使用stackoverflow(底部的链接)的建议进行故障排除,但没有一个对我有用。我希望有人对我可能犯的一个愚蠢的错误有所了解。

我尝试过只使用 json 编解码器,只使用 json 过滤器,以及两者。出于某种原因,我仍然收到这个 _jsonparsefailure。我该怎么做才能让它发挥作用?

提前致谢!

我的 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
        }
      }
    ]
  }
}

我的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 } 
}

我希望从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

How to use logstash's json filter?

【问题讨论】:

  • 对于发现这个问题但 没有 最终遇到问题的人,就像 this answer 中指出的那样,您可能需要转义非 ASCII 字符JSON 被发送到 Logstash。 非常令人困惑,相关的 Logstash 编解码器实际上似乎不支持未转义的非 ASCII 字符,尽管文档声称 UTF-8 受支持且默认字符编码是预期的。

标签: json filter logstash


【解决方案1】:

我在这里测试我的 JSON JSONLint。也许这会解决你的问题。我得到的错误是它需要字符串。

您的末尾似乎有一个不必要的逗号(',')。删除它或在此之后添加另一个 JSON 变量。

【讨论】:

  • 谢谢你,我实际上不得不截断文件并错过了逗号,我更正了上面的帖子
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-05-23
  • 1970-01-01
  • 1970-01-01
  • 2015-03-12
相关资源
最近更新 更多