Azure Logic Apps中动态移除请求体指定字段的实现方法
在Azure Logic Apps中动态移除指定字段并保留其余字段
场景说明
工作流数据源来自body('List_rows_present_in_a_table')?['value'],原始数据结构如下:
[ { "@odata.etag": "", "ItemInternalId": "bf73ba98-d392-424c-9dc1-f2be44e9d431", "Name": "Shuvendu", "Dept": "Developer" }, { "@odata.etag": "", "ItemInternalId": "3de1725d-d7cb-45fa-9855-713bbf8fdc23", "Name": "Debashish", "Dept": "DBA" } ]
需要动态移除@odata.etag和ItemInternalId字段,保留包括后续新增字段在内的所有其他字段,最终输出结构如下:
[ { "Name": "Shuvendu", "Dept": "Developer" }, { "Name": "Debashish", "Dept": "DBA" } ]
解决方案
使用Azure Logic Apps内置表达式,通过select与removeProperty函数组合实现动态字段移除:
核心表达式
select(body('List_rows_present_in_a_table')?['value'], removeProperty(removeProperty(item(), '@odata.etag'), 'ItemInternalId'))
操作步骤
- 在工作流中添加Compose动作(或直接在需要使用处理后数据的目标动作中调用该表达式)
- 将上述表达式粘贴到Compose的「输入」框内
- 运行工作流后,Compose的输出即为处理后的目标数组
表达式说明
select(body('List_rows_present_in_a_table')?['value'], ...):遍历源数组的每一个元素item():指代当前遍历到的数组对象removeProperty(item(), '@odata.etag'):移除当前对象中的@odata.etag字段- 嵌套的
removeProperty(..., 'ItemInternalId'):在移除@odata.etag的基础上,继续移除ItemInternalId字段
内容的提问来源于stack exchange,提问作者SHUVENDU
相关产品推荐
相关产品推荐

