CSV 转 JSON 转换器

立即将 CSV 文本转换为漂亮的 JSON。

// about

工具介绍

将 Excel 表格类 CSV 数据转换为 Web 开发常用的 JSON 格式,或将 JSON 转换回 CSV。非常适合在表格软件与网页应用之间传输数据。

如何使用

  1. 粘贴您的 CSV 文本或 JSON 代码。
  2. 确认分隔符设置(默认为逗号)。
  3. 点击“转换”并复制输出结果。

人们为何使用此工具

  • 方便在 Excel 数据与现代 Web 应用程序之间无缝切换。
  • 支持逗号、分号等多种列分隔符。
  • 无需安装 Excel 或插件,在线即时转换。

常见问题解答 (FAQ)

什么是 CSV 文件?

CSV 是用逗号分隔数据的纯文本表格,常用于 Excel 和电子表格软件。

CSV 的第一行必须包含表头吗?

第一行包含列名有助于在 JSON 中生成清晰的属性键名。

应该选择什么分隔符?

大多数文件使用标准逗号 (,),部分地区文件使用分号 (;)。

指南 · 数据 · 约 3 分钟

CSV 与 JSON:如何选择,以及转换时要注意什么

把电子表格导出的数据发给 API,或在 Excel 中打开 API 响应,都需要在 CSV 和 JSON 之间转换。了解两种格式的差异,可以避免数据在转换中受损。

CSV(逗号分隔值)是一张表。第一行是列名,之后每一行是一条记录,值之间用逗号分隔。它是存储扁平数据(每行列都相同)最简单、最轻量的方式。

name,city,score
Kim,Seoul,92
Lee,Busan,85

[
  {"name": "Kim", "city": "Seoul", "score": 92},
  {"name": "Lee", "city": "Busan", "score": 85}
]
CSV 与 JSON 的结构差异、Excel 打开 UTF-8 CSV 为何乱码、逗号和引号的转义规则,以及如何把嵌套数据展平。
阅读指南 →
用 AI 自己做

用 AI 亲手打造这个工具

想要自己的版本?把下面的任务提示词粘贴到 AI 聊天中,或将技能文件保存到 AI 编程助手。其中包含我们开发此工具时整理的功能、边界情况和测试用例。

提示词和技能以英文提供,AI 工具在任何语言环境下都能很好地理解。

AI 任务提示词

直接粘贴到 Claude、ChatGPT、Gemini 等 AI 聊天中即可。

You are an experienced full-stack web developer. Build a web tool called "CSV 转 JSON 转换器" that meets the requirements below.

## Goal

Build a converter between CSV and JSON.

## Core features

- CSV → JSON (array of objects) and JSON → CSV
- Auto-detect comma, semicolon or tab delimiters
- Header row on/off
- Optional conversion of numbers and booleans
- Download CSV with a UTF-8 BOM for Excel

## Inputs

- CSV or JSON text/file
- Delimiter, header and type options

## Outputs

- Converted data
- Row and column counts

## Edge cases and handling rules

- Follow RFC 4180 for quoted commas, line breaks and doubled quotes
- Keep values with leading zeros (postal codes) as strings
- Flatten nested JSON into dotted columns (user.name)
- Warn when rows have different column counts

## Implementation requirements

- Build it as a single page (HTML, CSS, JavaScript) that runs entirely in the browser, and never send the user's input to a server.
- Make the UI responsive and easy to use on mobile; label every input and keep everything keyboard accessible.
- Add a Copy button for results and show clear, friendly error messages for invalid input.
- Keep the core logic in functions separate from the UI so it can be unit-tested.

## Definition of done (test cases)

- '"Seoul, Korea"' stays a single value
- '01234' is not turned into a number
- Round-tripping keeps the same row count

First outline your implementation plan in at most five lines, then write the complete code, and finally explain how to check the test cases above.

技能 (SKILL.md)

在 Claude Code 等 AI 编程助手中保存为 .claude/skills/build-csv-json-converter/SKILL.md,以后开发或修改此工具时可重复使用。

---
name: build-csv-json-converter
description: Use when building or changing a CSV 转 JSON 转换器 tool. Build a converter between CSV and JSON.
---

# Build: CSV 转 JSON 转换器

## Goal

Build a converter between CSV and JSON.

## Workflow

1. Review the required features, inputs and outputs below and ask about anything missing first.
2. Implement the core logic as pure functions separate from the UI.
3. Check the logic against the test cases in the verification list.
4. Build a responsive UI with an input form, a result area and a Copy button.
5. Reproduce each edge case listed under Rules and refine the error messages.

## Core features

- CSV → JSON (array of objects) and JSON → CSV
- Auto-detect comma, semicolon or tab delimiters
- Header row on/off
- Optional conversion of numbers and booleans
- Download CSV with a UTF-8 BOM for Excel

## Inputs

- CSV or JSON text/file
- Delimiter, header and type options

## Outputs

- Converted data
- Row and column counts

## Rules

- Follow RFC 4180 for quoted commas, line breaks and doubled quotes
- Keep values with leading zeros (postal codes) as strings
- Flatten nested JSON into dotted columns (user.name)
- Warn when rows have different column counts
- Build it as a single page (HTML, CSS, JavaScript) that runs entirely in the browser, and never send the user's input to a server.

## Verification

- [ ] '"Seoul, Korea"' stays a single value
- [ ] '01234' is not turned into a number
- [ ] Round-tripping keeps the same row count

交给 AI 时的小技巧

  • 在第一行写明技术栈(如 React、Vue 或纯 HTML),生成的代码会更贴合你的项目。
  • 在接受代码前,请让 AI 运行列出的测试用例并展示结果。
  • 不要把真实密码、客户数据或 API 密钥粘贴到提示词中,请用示例值代替。