跳到主要内容

解析 CSVJSONPower AutomatePDF4me

PDF4me CSV 解析为 JSON 是一个 Power Automate 将以下操作转换为 CSV 文件整理成结构化格式。 JSON 具有三级头部优先级系统和可配置分隔符的数组。可用于馈送 CSV 导出到数据库, REST API或者无需在流程中编写自定义解析器即可使用 Excel。

此操作的作用

PDF4me CSV 解析为 JSON 读到 CSV 文件并返回一个 Base64编码 JSON 对象数组,其中列标题、跳过首行和区域性名称控制行和标题的解释方式。任何分隔符均有效,并且会优雅地处理格式错误的行,而不会导致流程失败。

相关博客文章
目前尚无关于此功能的博客文章——敬请期待。
在此期间,您可以浏览 PDF4me 博客,查看适用于各平台的教程和工作流程。
访问博客

我如何验证我的身份 Power Automate 流动?

每一个 PDF4me 行动 Power Automate 需要有效的连接。创建或选择一个包含您数据的连接。 PDF4me API 关键在于流程能够进行身份验证 CSV 安全地解析请求。

您不容错过的重要事实

头部处理严格遵循三级优先级原则。
如果提供列标题,则列标题优先显示(每个)。 CSV 行成为数据)。否则,“跳过第一行”设置为 true 时使用第一行。 CSV 将行作为标题。如果两行都为空,则标题会自动生成为 Column1、Column2 等。
文化名称是一个容易被忽略的高级参数
“区域名称”隐藏在“高级参数”下,与“列标题”和“跳过首行”并列,用于设置解释特定区域的数字和日期格式的语言环境。 CSV
解析是宽松的,而非严格的。
值少于标题的行将返回空字符串,值多于标题的行将忽略多余的值,格式错误的数据将返回一个空数组而不是抛出错误。
Power Automate PDF4me CSV - 解析为 JSON 操作已配置文件内容、文件名、CSV 分隔符和高级参数(列标题、跳过首行和区域性名称)。

映射文件内容和文件名,设置 CSV 选择分隔符,然后展开“列标题”、“跳过首行”和“区域名称”等高级参数。

参数

必需的: 文件内容、文件名和 CSV 必须提供分隔符。“列标题”、“跳过首行”和“区域性名称”是可选的高级参数。

范围必需的它的作用例子
File ContentRequiredBase64 content of the source CSV file, mapped from SharePoint, OneDrive, or an email attachment.[File Content from Get File]
File NameRequiredCSV filename including extension, used for processing and output identification.data.csv
CSV DelimiterRequiredCharacter or short string separating columns. Comma, semicolon, tab, and pipe are all supported, as are multi-character delimiters.,
Column HeadersOptionalComma-separated custom header names. When provided, every CSV line including the first is treated as data and Skip First Line is ignored.FullName,Age,Email
Skip First LineOptionalWhen true and Column Headers is empty, uses the first CSV line as headers and starts data from the second line. Default false.true
Culture NameOptionalLocale used to interpret region-specific number and date formats in the CSV content.en-US

输出字段

场地类型它包含什么
documentBase64The parsed JSON array, UTF-8 encoded and Base64 wrapped.
FileNameStringFixed output filename, "parsed_data.json".
SuccessBooleantrue if parsing completed, false if the action failed.
ErrorMessageStringError description, null when Success is true.
ErrorsArrayDetailed error objects with Code and Message, empty when Success is true.

常见错误信息是什么意思?

错误信息原因解决方案
Request is emptyRequest object is null.Provide a valid request object.
Document is emptyDocument object is null or CSV content is null.Provide valid CSV file content.
Encoding exceptionsCSV content is not UTF-8 encoded.Re-save or export the CSV file as UTF-8.
Empty array outputCSV content is empty or contains only a header row.Provide a CSV file with at least one data row.

如何设置解析 CSVPower Automate

  1. 添加 PDF4meCSV 解析为 JSON 致你 Power Automate 流动。
  2. 地图 文件内容文件名 来自之前的操作(SharePointOneDrive或电子邮件附件)。
  3. CSV分隔符 与源文件匹配(逗号、分号、制表符或竖线)。
  4. 扩张 高级参数 并设置 列标题 用于自定义名称,或 跳过第一行 使用文件自身的标题行。
  5. 运行流程,解码 文档 Base64 输出结果,并循环遍历这些结果。 JSON 数组 适用于每个

典型配置

工作流程示例Common Power Automate flow patterns using Parse CSV.
CSV 导入数据库
  1. A CSV 文件落入 SharePoint “导入”文件夹,触发流程。
  2. 解析 CSV 将其转换为 JSONCSV 分隔符设置为逗号,并启用“跳过首行”功能。
  3. 文档输出被解码并解析成各个部分。 JSON 物体。
  4. 对每个记录进行循环,并通过 SQL 连接器插入记录。
  5. 处理后的 CSV 已移至“存档”文件夹。
欧洲出口到 REST API
  1. 源系统通过电子邮件发送以分号分隔的内容 CSV 出口。
  2. 解析 CSV 运行 CSV 分隔符设置为分号,并启用“跳过首行”功能。
  3. 每个解析后的记录都会被发布到 REST API 以终点结束 HTTP
  4. 收集响应代码以标记任何失败的记录。
  5. 循环结束后,系统会通过电子邮件发送摘要。
将带有自定义标题的 CSV 文件转换为 Excel 文件
  1. 旧版报表以制表符分隔符的形式送达。 CSV 没有标题行。
  2. 解析 CSV 运行 CSV 分隔符设置为制表符,列标题已明确设置。
  3. 由此产生的 JSON 数组馈入 PDF4me 使用“添加行”操作填充 Excel 模板。
  4. 格式化后的Excel工作簿将通过电子邮件发送给利益相关者。

实用技巧

Column Headers overrides Skip First Line completely
If you set Column Headers, Skip First Line is ignored and every CSV row, including what looks like a header row, is treated as data. Do not set both expecting them to combine.
Match the delimiter exactly to the export locale
European CSV exports commonly use a semicolon instead of a comma, especially when the source system uses comma as the decimal separator. Check a sample row before hardcoding the delimiter.
Decode document before parsing further
The document output is Base64-encoded JSON text, not a ready-to-use object. Decode it first, then use Parse JSON to expose individual fields for Apply to each.
Set Culture Name for non-US number formats
If the CSV uses comma as a decimal separator or day-first dates, set Culture Name to match (for example de-DE or en-GB) so downstream conversions do not misread values.
Treat empty output as a signal, not a crash
An empty array back from Parse CSV usually means the file only had a header row or was empty, not that the flow failed. Check Success and Errors before assuming the source file is fine.

速查表

场地价值
ActionCSV - Parse to JSON
Header priorityColumn Headers > Skip First Line > auto-generated
Common delimiters, (comma) / ; (semicolon) / \t (tab) / | (pipe)
Output filenameparsed_data.json (fixed)
Output formatdocument (Base64 JSON array)
Malformed data behaviorReturns empty array, does not error

常见问题

How do I parse a CSV file to JSON in Power Automate?+
Add the PDF4me CSV - Parse to JSON action, map File Content and File Name from a prior action, set the CSV Delimiter, then choose Column Headers or Skip First Line for header handling. The action returns document, a Base64 JSON array you can decode and loop through.
What is the header priority order?+
Column Headers takes priority if provided, every CSV line including the first is treated as data. If Column Headers is empty and Skip First Line is true, the first CSV line becomes the headers. If both are empty, headers are auto-generated as Column1, Column2, and so on.
What happens with malformed or empty CSV data?+
CSV parsing is permissive. Rows with fewer values than headers are filled with empty strings, rows with more values than headers have the extras ignored, and empty or header-only CSV content returns an empty JSON array rather than an error.
What does the Culture Name parameter do?+
Culture Name is an advanced parameter that sets the locale used when interpreting the CSV content, useful when the source file uses region-specific number or date conventions that differ from the default parsing culture.
Can I parse semicolon or tab-delimited CSV files?+
Yes. CSV Delimiter accepts any character or short string, including semicolon for European exports, tab for TSV files, or pipe for database exports. Multi-character delimiters are also supported. See <a href="https://www.rfc-editor.org/rfc/rfc4180" target="_blank" rel="noopener noreferrer">RFC 4180, the common CSV format specification</a> and <a href="https://learn.microsoft.com/en-us/connectors/pdf4meconnect/" target="_blank" rel="noopener noreferrer">the PDF4me Power Automate connector reference</a> for background.

行业应用案例及应用

  • 遗留系统集成将旧系统中导出的 CSV 文件解析为 JSON 文件
  • API 数据源将 CSV 数据转换为 JSON 格式,以便 REST API 调用。
  • 数据库迁移解析 CSV 文件以进行数据库导入操作
  • 日志文件处理解析 CSV 格式的日志文件以进行分析

相关操作

在其他平台上执行相同任务

获取帮助