JSON ↔ CSV Converter

One input per line. Output is numbered to match the input order.
Pinned tools are listed in your favourites on the home page.Copies a link to this tool that carries your current input, so it opens ready to run.Gives you an iframe snippet for putting this tool on your own site.

Quoting follows RFC 4180: a field is wrapped in double quotes when it contains the delimiter, a quote or a newline, and embedded quotes are doubled. Type conversion is off by default so identifiers like 007 keep their leading zeros.

Ctrl+Enter Run  · Ctrl+Shift+C Copy  · Esc Clear

Understand JSON ↔ CSV Converter

这个转换器把 JSON 对象数组变成 CSV 表格,也能把 CSV 表格读回成 JSON。

How it works

数组中的每个对象成为一行,对象的键成为表头行,这就是为什么只有当 JSON 是扁平对象的数组时,表格才讲得通。字段按 RFC 4180 规定的方式加引号:任何含逗号、双引号或换行的值都会被双引号包裹,其中的双引号会被写两遍——She said "hi" 变成 "She said ""hi"""。反向读取 CSV 时,这层引号规则会被还原,而每个字段都会以字符串形式出现,因为 CSV 完全不携带类型信息。

When to use it

  • 把 API 响应放进电子表格,交给不想读 JSON 的人。
  • 把导出的 CSV 变成测试或种子脚本用的 JSON 夹具。
  • 把日志或事件导出扁平化,以便在 Excel 或 Google Sheets 中排序和筛选。
  • 用同事的工具真正能打开的格式,把数据样本交给他们。

Watch out for

  • CSV 是扁平的,JSON 不是。行内嵌套的对象或数组没有对应的单元格可放,因此请在转换之前而不是之后把这些键扁平化。
  • 两个方向都会丢失类型。像 007 这样带前导零的 ID、很长的数字 ID 和日期,回来都会是字符串——而电子表格可能在打开文件的那一刻就把它们重新格式化。
  • 以 =、+、- 或 @ 开头的字段会被 Excel 和 Google Sheets 当作公式。这就是 CSV 注入,一旦这些值来自用户,它就要紧了。
  • 不存在唯一的 CSV 方言。在用逗号作小数点的地区,分号才是常规分隔符;而 Excel 往往需要 UTF-8 字节序标记,才能正确显示带重音的字符。

Frequently Asked Questions

如何把 JSON 转换成 CSV?

粘贴一个对象数组并选择分隔符。所有记录中出现过的每一个键都会成为一列,顺序按首次出现排列,因此只在最后一条记录里出现的键仍会得到一列,而不会被丢弃。嵌套对象会以 JSON 形式写在单元格内。

转换器如何处理值中的逗号?

按照 RFC 4180,任何含有分隔符、双引号或换行的字段都会被双引号包裹,值内部的引号会被写成两个。Excel、Google Sheets 和所有标准 CSV 读取器期望的正是这种格式。

为什么 CSV 转成 JSON 后我的数字变成了字符串?

CSV 没有类型——每个字段都是文本——因此除非你打开类型转换,转换器会把值保留为字符串。即便打开了,带前导零的值仍会保持字符串,因为把邮编或账号变成数字是一个丢数据的缺陷。

How to Use JSON ↔ CSV Converter

  1. Paste or type your input in the input area above.
  2. The tool processes your input automatically or click Run.
  3. Copy or download the result using the action buttons.
  4. Use Ctrl+Enter to run quickly from the keyboard.