gpt4 book ai didi

json - Logstash:解析通过Web服务(如twitter/facebook等)接收到的Json数据时,解析失败

转载 作者:行者123 更新时间:2023-12-02 23:29:02 30 4
gpt4 key购买 nike

我收到来自Twitter的Web服务数据并记录到文件,之后需要将该数据发送到Logstash,以便可以将它们索引到Elasticsearch。

我正在使用下面的配置,这给jsonparsefailure与异常为

JSON parse failure. Falling back to plain-text {:error=>#> LogStash::Json::ParserError: Unexpected character (':' (code 58)): expected a >valid value (number, String, array, object, 'true', 'false' or 'null')



我的logstash conf文件看起来像:
input
{
file
{
path => ["/mnt/volume2/ELK_Prashant/at/events.json"]
codec => json
type => json
start_position => "beginning"
sincedb_path => "/dev/null"
}
}
output
{
stdout { codec => rubydebug }
}

可以使用以下示例从 https://dev.twitter.com/rest/reference/get/search/tweets引用events.json中的数据: events.json
[
{ "location": "LA, CA",
"follow_request_sent": null,
"profile_link_color": "0084B4",
"is_translator": false,
"id_str": "137238150",
"entities": {
"url": {
"urls": [
{
"expanded_url": null,
"url": ""
}
]
}
}
}
]

最佳答案

从示例events.json文件中,很明显,您正在使用完整的json对象作为Logstash file插件的输入,但是该插件默认情况下假设每个事件都是单行,因此,它只能检测即将到来的新事件。并跟踪当前位置。

因此,您的输入文件应如下所示,其中每个事件都由换行符分隔

{"location":"LA, CA","follow_request_sent":null,"profile_link_color":"0084B4","is_translator":false,"id_str":"137238150","entities":{"url":{"urls":[{"expanded_url":null,"url":""}]}}}
{"location":"LA, CA","follow_request_sent":null,"profile_link_color":"0084B4","is_translator":false,"id_str":"137238150","entities":{"url":{"urls":[{"expanded_url":null,"url":""}]}}}
{"location":"LA, CA","follow_request_sent":null,"profile_link_color":"0084B4","is_translator":false,"id_str":"137238150","entities":{"url":{"urls":[{"expanded_url":null,"url":""}]}}}

或者您必须在输入插件中使用多行编解码器或过滤器。可以找到更多信息 here

关于json - Logstash:解析通过Web服务(如twitter/facebook等)接收到的Json数据时,解析失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38705585/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com