只需在下方表单中上传您的 CSV 文件,它就会自动转换为 YAML 文件。在工具选项中,您可以指定字段分隔符、字段引号和注释符,以使工具适应自定义 CSV 格式。此外,您还可以选择输出 YAML 格式:保留 CSV 标头或不包含 CSV 标头。
Input CSV
Output YAML
工具选项
Adjust CSV input
Enter the character used to delimit columns in the CSV file.
Enter the quote character used to quote the CSV fields.
Enter the character indicating the start of a comment line. Lines starting with this symbol will be skipped.
Conversion Options
Keep the first row as column names.
Enable to prevent the conversion of empty lines in the input CSV file.
Adjust YAML indentation
Set the number of spaces to use for YAML indentation.
What is a 将 CSV 转换为 YAML?
此工具可将 CSV(逗号分隔值)数据转换为 YAML(另一种标记语言)数据。CSV 是一种简单的表格格式,用于表示由行和列组成的矩阵式数据类型。而 YAML 是一种更高级的格式(实际上是 JSON 的超集),它能够创建更易于序列化的数据,并且支持列表、字典和嵌套对象。此程序支持多种 CSV 输入格式——输入数据可以使用逗号分隔(默认)、分号分隔、竖线分隔或使用其他完全不同的分隔符。您可以在选项中指定数据使用的确切分隔符。同样,您可以在选项中指定用于包装 CSV 字段的引号字符(默认为双引号)。您还可以通过在选项中指定注释符号来跳过以注释开头的行。这样可以通过跳过不必要的行来保持数据整洁。有两种方法可以将 CSV 转换为 YAML。第一种方法将每个 CSV 行转换为 YAML 列表。第二种方法从第一个 CSV 行中提取标题,并根据这些标题创建带有键的 YAML 对象。您还可以通过指定 YAML 结构缩进的空格数来自定义输出 YAML 格式。如果您需要执行反向转换,即将 YAML 转换为 CSV,可以使用我们的“将 YAML 转换为 CSV”工具。CSV 真棒!
将 CSV 转换为 YAML 示例
点击尝试!
In this example, we transform a short CSV file containing a music playlist into structured YAML data. The input CSV contains five records with three columns each and the output YAML contains five lists of lists (one list for each CSV record). In YAML, lists start with the "-" symbol and the nested lists are indented with two spaces
Adjust CSV input
Enter the character used to delimit columns in the CSV file.
Enter the quote character used to quote the CSV fields.
Enter the character indicating the start of a comment line. Lines starting with this symbol will be skipped.
Conversion Options
Keep the first row as column names.
Enable to prevent the conversion of empty lines in the input CSV file.
Adjust YAML indentation
Set the number of spaces to use for YAML indentation.
In this example, we are working with CSV data that summarizes key properties of three planets in our solar system. The data consists of three columns with headers "planet", "relative mass" (with "1" being the mass of earth), and "satellites". To preserve the header names in the output YAML data, we enable the "Transform Headers" option, creating a YAML file that contains a list of YAML objects, where each object has three keys: "planet", "relative mass", and "satellites".
Adjust CSV input
Enter the character used to delimit columns in the CSV file.
Enter the quote character used to quote the CSV fields.
Enter the character indicating the start of a comment line. Lines starting with this symbol will be skipped.
Conversion Options
Keep the first row as column names.
Enable to prevent the conversion of empty lines in the input CSV file.
Adjust YAML indentation
Set the number of spaces to use for YAML indentation.
In this example, we convert a CSV file with non-standard formatting into a regular YAML file. The input data uses a semicolon as a separator for the "product", "quantity", and "price" fields. It also contains empty lines and lines that are commented out. To make the program work with this custom CSV file, we input the semicolon symbol in the CSV delimiter options. To skip comments, we specify "#" as the symbol that starts comments. And to remove empty lines, we activate the option for skipping blank lines (that do not contain any symbols). In the output, we obtain a YAML file that contains a list of three objects, which use CSV headers as keys. Additionally, the objects in the YAML file are indented with four spaces.
Adjust CSV input
Enter the character used to delimit columns in the CSV file.
Enter the quote character used to quote the CSV fields.
Enter the character indicating the start of a comment line. Lines starting with this symbol will be skipped.
Conversion Options
Keep the first row as column names.
Enable to prevent the conversion of empty lines in the input CSV file.
Adjust YAML indentation
Set the number of spaces to use for YAML indentation.