将JSONL文件加载为JSON对象 [英] Loading JSONL file as JSON objects

查看:437
本文介绍了将JSONL文件加载为JSON对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将JSONL文件作为python中的JSON对象加载.有一个简单的方法吗?

I want to load a JSONL file as JSON objects in python. Is there an easy way to do so?

推荐答案

通常,以下代码将为您工作:

In general the code below shall work for you:

import json

result = [json.loads(jline) for jline in jsonl_content.split('\n')]

如果这是响应对象,则结果将是:

If that's the response object the result would be:

result = [json.loads(jline) for jline in response.read().split('\n')]

这篇关于将JSONL文件加载为JSON对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆