gpt4 book ai didi

json - jq : continue parsing ignoring invalid literals

转载 作者:行者123 更新时间:2023-12-03 09:05:03 34 4
gpt4 key购买 nike

我正在使用jq的流传输功能来从大型压缩文件中解析JSON。我收到的JSON并不是错误的,我已经对其进行了几次验证。在某些行之后解析压缩文件后,我继续收到如下错误:

jq: parse error: Invalid numeric literal at line 3524768, column 0

我验证了3524768行,它显示了一个非常好的JSON。
{"created_at":"Mon Jul 18 08:02:46 +0000 2016","id":754949520631496704,"id_str":"754949520631496704","text":"je regarde le monde de charlotte et si je le finis t\u00f4t je regarde Caroline","source":"\u003ca href=\"http:\/\/twitter.com\/download\/iphone\" rel=\"nofollow\"\u003eTwitter for iPhone\u003c\/a\u003e","truncated":false,"in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"user":{"id":2760400101,"id_str":"2760400101","name":"m.d.r","screen_name":"eoalfd","location":"nevers","url":null,"description":"emmenez-moi voir odezenne | hugo&mel","protected":false,"verified":false,"followers_count":683,"friends_count":262,"listed_count":15,"favourites_count":6493,"statuses_count":42605,"created_at":"Wed Sep 03 14:55:50 +0000 2014","utc_offset":-25200,"time_zone":"Pacific Time (US & Canada)","geo_enabled":true,"lang":"fr","contributors_enabled":false,"is_translator":false,"profile_background_color":"000000","profile_background_image_url":"http:\/\/abs.twimg.com\/images\/themes\/theme1\/bg.png","profile_background_image_url_https":"https:\/\/abs.twimg.com\/images\/themes\/theme1\/bg.png","profile_background_tile":false,"profile_link_color":"F5ABB5","profile_sidebar_border_color":"000000","profile_sidebar_fill_color":"000000","profile_text_color":"000000","profile_use_background_image":false,"profile_image_url":"http:\/\/pbs.twimg.com\/profile_images\/753684703450923008\/U-11Brew_normal.jpg","profile_image_url_https":"https:\/\/pbs.twimg.com\/profile_images\/753684703450923008\/U-11Brew_normal.jpg","profile_banner_url":"https:\/\/pbs.twimg.com\/profile_banners\/2760400101\/1468624180","default_profile":false,"default_profile_image":false,"following":null,"follow_request_sent":null,"notifications":null},"geo":null,"coordinates":null,"place":null,"contributors":null,"is_quote_status":false,"retweet_count":0,"favorite_count":0,"entities":{"hashtags":[],"urls":[],"user_mentions":[],"symbols":[]},"favorited":false,"retweeted":false,"filter_level":"low","lang":"fr","timestamp_ms":"1468828966659"}

我正在应用的过滤器(适用于此特定行)如下:
jq '. as $parent |.text | match("#(?!(p[0-9])|([0-9])|(q[0-9]|_))[a-zA-Z0-9]+") as $result | {"time":$parent.timestamp_ms,"string":$result.string}'

实际上,只要我将3524768行提取到一个隔离的文件中并运行我的jq解析器,它就可以正常工作!尽管出现此数字文字错误,有什么办法可以使我的jq解析器运行?也许,忽略它并继续下一行?
我已经坚持了几天,任何帮助都会很棒。

最佳答案

可能错误消息中的行号偏移了一个。

无论如何,要从错误中恢复,可以使用如下所示的惯用法:

def process:
try (inputs | type)
catch ("error at line \(input_line_number)", process);

process

使用这样的程序,通常会使用-n命令行参数来调用jq。



使用过滤器,您可以编写:
def myfilter:
. as $parent
| .text
| match("#(?!(p[0-9])|([0-9])|(q[0-9]|_))[a-zA-Z0-9]+") as $result
| {"time":$parent.timestamp_ms,"string":$result.string} ;

def process:
try (inputs | myfilter)
catch ("error at line \(input_line_number)", process);

process

关于json - jq : continue parsing ignoring invalid literals,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62418421/

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