问题描述
我正在尝试按其字段过滤 jsonl.gz 文件。这是我阅读文件内容时的文件格式:
{"type":"endpoint.event.a","process_guid":"12345","process_publisher":[{"name":"Trend."}]}
{"type":"endpoint.event.b","process_guid":"1234","process_guid":"12","process_publisher":[{"name":"Trend "}]}
{"type":"endpoint.event.c","process_guid":"123","process_publisher":[{"name":"Trend"}]}
我希望能够进行归档,因此在打印其内容时,可以选择要查看的内容。例如,我只想打印出“类型”为“ endpoint.event.b”的内容。输出为:
{"type":"endpoint.event.b","process_publisher":[{"name":"Trend "}]}
我尝试获取它,但是我一直遇到错误。我尝试了json.loads(content),但是它给出了一个错误:
raise JSONDecodeError("Extra data",s,end)
json.decoder.JSONDecodeError: Extra data: line 2 column 1 (char 1531)
我也尝试过使用content ['type'] =='endpoint.event.b',但效果不佳。
这是我的代码,用于打印出内容:
import boto3
import json
from io import BytesIO
import io
import gzip
from gzip import GzipFile
obj1 = s3_resource.Object(BUCKET_NAME,key)
with gzip.GzipFile(fileobj=obj1.get()["Body"],mode='rb') as gzipfile:
contents = gzipfile.read().decode('utf-8')
print(contents)
是否有针对给定参数过滤此类数据的想法或建议?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)