CSV 转 JSON 转换器
在浏览器中即时将 CSV 数据转换为 JSON 对象数组。
CSV is the lowest common denominator for data exchange — every tool exports it — but most modern application code expects JSON. Converting a CSV export to a JSON array unlocks it for use in JavaScript front-ends, Node.js scripts, REST API mock data, and NoSQL databases that store documents rather than rows.
This converter reads a CSV with a header row, maps each subsequent row to a JSON object keyed by the header values, and outputs a clean JSON array. It is the fastest way to turn a spreadsheet export into seed data for a database, a fixture for a test suite, or a payload for a bulk API import — without writing a throwaway script.
如何在线将 CSV 转换为 JSON
- 1
粘贴您的 CSV
将 CSV 文本粘贴到输入框中。工具自动检测分隔符(逗号、分号、制表符或竖线)。
- 2
将标题映射到键名
默认情况下,第一行成为 JSON 对象的键名。启用无标题行选项可生成数字键名。
- 3
复制 JSON 输出
复制格式化的 JSON 输出,或使用切换按钮在 JSON 格式化工具中打开结果。
How CSV-to-JSON Conversion Works
The parser reads the first row as column names and then maps each subsequent row positionally. Extra columns beyond the header are discarded; missing columns at the end of a short row produce null values rather than throwing an error. The challenge lies in type inference: should `"42"` become the number `42` or the string `"42"`? This converter performs conservative type coercion — plain integers and floats become JSON numbers, `"true"` and `"false"` become booleans, and everything else stays a string.
Quoted fields are unescaped per RFC 4180, including doubled double-quotes and embedded newlines. The output array is pretty-printed by default so it is immediately readable and diffable in version control, with an option to compact it for smaller file size when the result is destined for an API payload.
为什么使用 FileCrank CSV 转 JSON?
- ✓ 自动检测分隔符,支持手动覆盖。
- ✓ 第一行自动成为 JSON 键名。
- ✓ 格式化输出,可直接粘贴到代码中。
- ✓ 完全在浏览器中运行——不向任何服务器发送数据。
功能与规格
常见问题
CSV 的第一行会成为 JSON 的键名吗?
是的。默认情况下第一行被视为标题行,成为每个 JSON 对象中的键名。如果您的 CSV 没有标题行,启用相应选项,工具将生成数字键名(col_0、col_1 等)。
如果 CSV 各行的列数不同会怎样?
列数少于标题的行,缺失键的值为 null。列数多于标题的行,多余的值将被忽略并显示警告。
如何处理使用分号而非逗号的 CSV?
工具自动检测分隔符。如果自动检测有误,打开分隔符选项手动选择分号。
JSON 输出是压缩还是格式化的?
默认情况下输出是格式化的,便于阅读。如需紧凑的单行版本,可复制输出后使用 JSON 格式化工具进行压缩。
Browser Converter vs. Python csv Module vs. Dedicated ETL
Python's `csv` module combined with `json.dumps` gives you full control but requires writing and running code. Dedicated ETL tools add scheduling and monitoring that are overkill for a one-time conversion. Spreadsheet macros can do it but produce inconsistent output depending on locale settings. A browser-based converter is the fastest path from a CSV file to a valid JSON array when you need the result immediately and reproducibility is not a requirement.
相关工具
FileCrank CSV 转 JSON 转换器将 CSV 行转换为 JSON 对象数组,自动检测分隔符并将第一行映射为对象键名,完全在浏览器中运行。
Advertisement