从jsonarrays或json行缓慢地流式处理对象。。

json-streams的Python项目详细描述


json流

Build StatuscodecovBuild & PublishPyPI status

读写JSON延迟,尤其是JSON数组。在

处理两种JSON格式:

[{"a":1},{"a":2}]

以及JSON行格式:

^{pr2}$

使用orjson或{}(如果存在),否则使用标准json。在

使用

安装

# Using standard json
pip install json-streams

# Using orjson
pip install json-streams[orjson]# Using ujson
pip install json-streams[ujson]

此库首选以二进制模式打开的文件。 因此,所有dumps-方法都返回bytes。在

所有loads方法处理str参数。 如果使用orjson库,还可以将bytes或{}传递给loads。 目标是使所有loads处理strbytes和{}。在

示例

允许您使用json.load和{}与 json和json行文件以及转储生成器。在

importjson_streams# This command tries to guess format and opens the filedata=json_streams.load_from_file("data.json")# or data.jsonl# Write to file, again guessing formatjson_streams.dump_to_file(data,"data.jsonl")
fromjson_streamsimportjson_iter,jsonl_iter# Open and read the file without guessingdata=json_iter.load_from_file("data.json")# Process file# Write to file without guessingjsonl_iter.dump_to_file(data,"data.jsonl")
importjson_streamsdefprocess(data):forentryindata:# processyieldentrydefread_process_and_write(filename_in,filename_out):json_streams.dump_to_file(process(json_streams.load_from_file(filename_in)),filename_out)

发展

复制回购后,只需运行

$ make test

要设置虚拟环境, 安装开发依赖项 然后运行单元测试。在

注意:如果在激活的虚拟环境中运行该命令, 而是使用这种环境。在

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java如何读取、验证和移动数据。csv文件?   用于在线蛇游戏的java解析scaing   java JavaFX:在窗口上移动元素(阶段)调整大小   mysql如何使用java中的IOUtils包在jsp中显示多个图像?   Java dateFormat不可解析日期异常   spring mvc java。执行单元测试时lang.AssertionError   java在一个webapp中运行多个调度器有什么问题吗?   JAVAlang.ArrayIndexOutofBounds异常:1未来。get()多线程   java使用MDC或spring boot中的任何过滤器屏蔽日志消息中的密码,而不使用logback。xml文件   与应用服务器的java AJP和SSL通信   java Hibernate更新列表中的特定对象   Java小程序:使用keylistener移动多边形   java访问是一个独立于MainActivity的进程   来自服务器的java重复密钥或完整性约束冲突消息:“列“volume”不能为null”   java是否有任何方法可以确保在Flink on job cancel with savepoint上通知所有检查点侦听器检查点完成?