JSON 转 CSV 转换器
这个 JSON 转 CSV 转换器可将 JSON 数据转换为逗号分隔值格式,用于电子表格和数据分析。粘贴 JSON 数组或对象,即可获得格式正确的 CSV 输出,支持自动检测标题和自定义分隔符。
JSON to CSV Converter
Convert JSON arrays of objects to CSV format
Frequently Asked Questions
如何将JSON转换为CSV?
将JSON转换为CSV时,从JSON对象中提取键作为CSV标题,然后将每个对象的值映射到对应的行。对于像[{"name":"Alice","age":30}]这样的JSON数组,输出是以"name,age"为标题行、"Alice,30"为数据行的CSV。我们的工具自动处理此过程,包括嵌套对象的扁平化。
嵌套JSON能转换为平面CSV吗?
是的,嵌套JSON可以扁平化为CSV格式。嵌套属性通常在列标题中用点符号表示。例如,{"user":{"name":"Alice","address":{"city":"NYC"}}}变为"user.name"和"user.address.city"列。对象中的数组可以作为逗号分隔的值连接,或拆分为多个编号列。
JSON数组在CSV转换中如何处理?
当JSON属性包含数组时,有几种方法:数组可以序列化为单个CSV单元格中的JSON字符串,用分隔符(如分号)连接,或展开为多个编号列(如"tags.0"、"tags.1")。最佳方法取决于CSV在下游的使用方式。
JSON转CSV时null值如何处理?
JSON中的null值通常在CSV输出中转换为空单元格。不会插入字符串"null",因为这可能与实际文本数据混淆。同样,某些JSON对象中未定义的属性(当对象具有不同结构时)会在这些列中产生空单元格。布尔值被转换为字符串表示"true"和"false"。
如何将JSON导出到Excel?
要将JSON数据导入Excel,首先使用JSON转CSV转换器将其转换为CSV格式。然后在Excel中打开CSV文件,Excel会自动将逗号分隔的数据解析为列。或者,Excel可以通过Power Query(获取数据>从JSON)直接导入JSON,它可以自动处理嵌套结构和数据类型检测。
什么是JSON扁平化?
JSON扁平化是将嵌套的层次化JSON结构转换为平面单层对象的过程。每个嵌套路径变为以点分隔的键。例如,{"a":{"b":{"c":1}}}扁平化为{"a.b.c":1}。这对于CSV转换至关重要,因为CSV本质上是不能直接表示层次结构的平面表格格式。
JSON和CSV哪个更高效?
对于平面表格数据,CSV空间效率更高,因为它的开销很小(只有逗号和换行符)。JSON对每个对象重复键名,增加了相当大的开销。但JSON对于稀疏数据(许多字段为空)和复杂嵌套结构更高效。对于有10列1000行的数据集,CSV可以比等效的JSON小30-50%。
JSON to CSV Converter
About the JSON to CSV Converter
The JSON to CSV Converter transforms JSON arrays of objects into CSV (Comma-Separated Values) format. CSV is widely used for data exchange between applications, spreadsheets, and databases. This tool handles nested objects by flattening them with dot notation, ensuring all your data is preserved in the conversion.
How to Use
- Paste your JSON array of objects into the input field
- Select your preferred delimiter (comma, tab, or semicolon)
- Toggle whether to include column headers in the output
- The CSV output is generated in real time
- Copy the result to clipboard or download as a .csv file
Features
- Real-time conversion as you type or paste
- Automatic flattening of nested objects using dot notation
- Proper CSV escaping for fields containing delimiters, quotes, or newlines
- Multiple delimiter options: comma, tab, and semicolon
- Optional header row inclusion
- One-click copy and file download
Handling Nested Objects
When your JSON contains nested objects, the converter flattens them using dot notation. For example:
{ "user": { "name": "Alice", "address": { "city": "NYC" } } }
Becomes columns: user.name, user.address.cityArrays within objects are serialized as JSON strings to preserve their structure in the CSV output.
Delimiter Options
- Comma (,) — Standard CSV format, compatible with most applications
- Tab — TSV format, useful when data contains commas
- Semicolon (;) — Common in European locales where comma is used as decimal separator
Common Use Cases
- Exporting API response data to spreadsheets
- Preparing data for import into databases
- Converting configuration data for analysis tools
- Transforming log data for reporting
- Data migration between systems using different formats