GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - eastyou/jsonl-csv: JSONL 与 CSV 双向流式转换 CLI,适合大文件与管道处理

BranchesTags
Open more actions menu

Latest commit

 

History

2 Commits
2 Commits

Folders and files

NameName
Last commit message
Last commit date
.github/workflows
.github/workflows
 
 
jsonlcsv
jsonlcsv
 
 
tests
tests
 
 
.gitignore
.gitignore
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
pyproject.toml
pyproject.toml
 
 

Repository files navigation

jsonl-csv

CI License: MIT Python

JSONL 与 CSV 双向转换的命令行工具,流式处理,适合大文件和管道。

日志、模型输出、数据导出经常是 JSONL 格式,而 Excel / 数据库更习惯 CSV。jsonlcsv 不把文件读进内存,几 GB 的文件也能稳定转换,并且会严格报告第几行出了什么问题。

特性

  • 流式处理:边读边写,内存占用与文件大小无关
  • 双向转换:to-csv 与 to-jsonl 两条命令
  • 类型推断:可选把 1、1.5、true、null 还原成 JSON 类型
  • 嵌套字段:数组/对象会序列化成紧凑 JSON 放进单元格
  • 严格校验:错误信息带行号;未知字段默认报错,可用 --drop-extra 忽略
  • 管道友好:默认读写标准输入输出
  • 零依赖:只使用 Python 标准库,Python 3.9+

安装

pip install "git+https://github.com/eastyou/jsonl-csv.git"

本地使用:

git clone https://github.com/eastyou/jsonl-csv.git
cd jsonl-csv
python3 -m pip install -e .

不安装也能运行:python3 -m jsonlcsv to-csv -i data.jsonl

使用

$ cat users.jsonl
{"name":"张三","age":18,"vip":true}
{"name":"李四","age":20,"vip":false}

$ jsonlcsv to-csv -i users.jsonl
name,age,vip
张三,18,true
李四,20,false
# 指定列顺序(也用于约束输出结构)
jsonlcsv to-csv -i users.jsonl --columns name,vip,age

# 大文件管道处理
cat events.jsonl | jsonlcsv to-csv > events.csv

# CSV 转 JSONL,并推断数字与布尔类型
jsonlcsv to-jsonl -i events.csv --infer-types

# 使用分号分隔
jsonlcsv to-csv -i users.jsonl --delimiter ";"

# 忽略第一行之外的额外字段
jsonlcsv to-csv -i mixed.jsonl --drop-extra

参数

jsonlcsv to-csv

参数 说明
-i, --input FILE 输入文件,默认标准输入
-o, --output FILE 输出文件,默认标准输出
--columns A,B 指定列顺序,默认使用第一行的字段
--delimiter CHAR 分隔符,默认 ,
--drop-extra 忽略未声明的字段,默认报错

jsonlcsv to-jsonl

参数 说明
-i, --input FILE 输入文件,默认标准输入
-o, --output FILE 输出文件,默认标准输出
--infer-types 推断整数、浮点数、布尔值和 null

退出码

退出码 含义
0 转换成功
2 参数错误、文件读写失败或数据格式错误

转换规则

JSON 值 CSV 单元格
null 空字符串
true / false true / false
数字 原样输出
字符串 原样输出(含逗号、引号、换行时由 CSV 规则转义)
数组 / 对象 紧凑 JSON,例如 {"a":1}
  • 表头默认取自第一条记录,之后出现的字段若不匹配会报错并提示行号
  • 需要稳定列结构时,请显式传入 --columns
  • to-jsonl 只有在 --infer-types 时才会把文本转成数字/布尔;否则全部按字符串输出

作为库使用

import io
from jsonlcsv import jsonl_to_csv

source = io.StringIO('{"a":1,"b":2}\n')
destination = io.StringIO()
count = jsonl_to_csv(source, destination)
print(count, destination.getvalue())

开发与测试

python3 -m unittest discover -s tests -v

License

MIT © 2026 eastyou

About

JSONL 与 CSV 双向流式转换 CLI,适合大文件与管道处理

Topics

clicsvdatajsonlpython

Resources

Readme
MIT license
Activity

Stars

0 stars

Watchers

0 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.