gpt4 book ai didi

python - 将 JSONL 文件加载为 JSON 对象

转载 作者:太空宇宙 更新时间:2023-11-03 12:53:56 25 4
gpt4 key购买 nike

我想在 python 中加载一个 JSONL 文件作为 JSON 对象。有没有简单的方法来做到这一点?

最佳答案

包括文件操作在内的完整步骤,适合我这样的新手

假设您有一个 .jsonl 文件,例如:

{"reviewerID": "A2IBPI20UZIR0U", "asin": "1384719342", "reviewerName": "cassandra tu \"Yeah, well, that's just like, u...", "helpful": [0, 0], "reviewText": "Not much to write about here, but it does exactly what it's supposed to. filters out the pop sounds. now my recordings are much more crisp. it is one of the lowest prices pop filters on amazon so might as well buy it, they honestly work the same despite their pricing,", "overall": 5.0, "summary": "good", "unixReviewTime": 1393545600, "reviewTime": "02 28, 2014"}
{"reviewerID": "A14VAT5EAX3D9S", "asin": "1384719342", "reviewerName": "Jake", "helpful": [13, 14], "reviewText": "The product does exactly as it should and is quite affordable.I did not realized it was double screened until it arrived, so it was even better than I had expected.As an added bonus, one of the screens carries a small hint of the smell of an old grape candy I used to buy, so for reminiscent's sake, I cannot stop putting the pop filter next to my nose and smelling it after recording. :DIf you needed a pop filter, this will work just as well as the expensive ones, and it may even come with a pleasing aroma like mine did!Buy this product! :]", "overall": 5.0, "summary": "Jake", "unixReviewTime": 1363392000, "reviewTime": "03 16, 2013"}

这段代码应该可以工作:

import json

with open('./data/my_filename.jsonl', 'r') as json_file:
json_list = list(json_file)

for json_str in json_list:
result = json.loads(json_str)
print(f"result: {result}")
print(isinstance(result, dict))

关于.jsonl文件:
http://jsonlines.org/

关于python - 将 JSONL 文件加载为 JSON 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50475635/

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