python里ndJSON格式数据的读取与保存
json和ndJson样例
# json可视化样例
[
{"1": "one"},
{"2": "two"},
{"3": "three"},
]
# ndJson可视化样例
{"1": "one"}
{"2": "two"}
{"3": "three"}
ndJson文件的读取
# 需要安装ndjson包:pip install ndjson
import ndjson
anno_data = ndjson.load(open(/your/ndjson/path),"r"))
ndJson文件的保存
import ndjson
data = [
{"1": "one"},
{"2": "two"},
{"3": "three"},
]
ndjson.dump(data, open(/your/ndjson/save/path, 'w'), ensure_ascii=False)
# 保存文件可视化如下
{"1": "one"}
{"2": "two"}
{"3": "three"}