如何在Logic App中解析JSON对象/数组?需处理notes数组
问题描述
从HTTP请求接收的JSON对象中,无法解析其中的notes数组,仅希望解析该数组内的变量。
示例Payload
{ "body": { "notes": [ { "id": 777, "title": "Prep AM Consult - Consult Scheduled For 8/25/21", "body": ":: Participant:", "type": "Consult", "contact_id": 641, "user_id": 10457, "last_updated_by": { "user_id": 10457, "given_name": "Test", "family_name": "One" }, "date_created": "2021-08-25T18:00:39Z", "last_updated": "2021-08-25T18:00:39Z" }, { "id": 779, "title": "AM Consult - Date of Original Consult 8/25/21", "body": ":: Participants", "type": "Consult", "contact_id": 641, "user_id": 10457, "last_updated_by": { "user_id": 10457, "given_name": "Test", "family_name": "Two" }, "date_created": "2021-08-25T18:29:14Z", "last_updated": "2021-08-25T18:29:14Z" } ], "count": 9, "next": "https://api.infusionsoft.com/", "previous": "https://api.infusionsoft.com/" } }
Azure生成的Schema
{ "properties": { "count": { "type": "integer" }, "next": { "type": "string" }, "notes": { "items": { "properties": { "body": { "type": "string" }, "contact_id": { "type": "integer" }, "date_created": { "type": "string" }, "id": { "type": "integer" }, "last_updated": { "type": "string" }, "last_updated_by": { "properties": { "family_name": { "type": "string" }, "given_name": { "type": "string" }, "user_id": { "type": "integer" } }, "type": "object" }, "title": { "type": "string" }, "type": { "type": "string" }, "user_id": { "type": "integer" } }, "required": [ "id", "title", "body", "type", "contact_id", "user_id", "last_updated_by", "date_created", "last_updated" ], "type": "object" }, "type": "array" }, "previous": { "type": "string" } }, "type": "object" }
疑问
最佳方法是否是创建CSV表格来加载这些数据?如果是,是否需要先为notes创建变量?
解答
- CSV是否是最佳选择?
CSV是合适的方案,但需结合后续需求判断:
- 如果要导出数据供他人查看、导入到表格工具分析,或是同步到依赖CSV格式的系统,CSV是高效实用的选择。
- 如果后续还要对数据做编程层面的过滤、转换等操作,建议先提取
notes数组为独立数据集,再根据需求决定是否转CSV,灵活性更高。
- 是否需要先为notes创建变量?
是的,必须先提取notes数组作为单独变量/数据集:
- 整个JSON结构嵌套较深,
notes位于body对象下,需先定位到response.body.notes(对应实际路径),将该数组单独提取出来,才能开展后续的CSV转换或其他处理。 - 提取完成后,可通过Azure内置工具(比如Logic Apps的
Select操作、Data Factory的映射功能)或代码(如Python的pandas库)将数组转换为CSV格式;处理嵌套的last_updated_by对象时,可将其展开为独立列(例如last_updated_by_user_id、last_updated_by_given_name)。
内容的提问来源于stack exchange,提问作者Shane Goodhew
相关产品推荐
相关产品推荐

