【问题标题】:How can i remove empty object in an array in Azure Logic apps如何在 Azure 逻辑应用程序中删除数组中的空对象
【发布时间】:2022-10-13 18:41:41
【问题描述】:

我只想删除数组中的空对象,然后再将其发送到另一个 HTTP 请求

  "documentId": "87f1bf4b-190a-40dd-b155-89b7530160ad",
  "tags": [
    {
      "Title": "Expiration Date",
      "AKA": "",
      "Value": "September 25, 1980",
      "Content": "Expired September 25, 1980",
      "path": "//Document/Sect/P",
      "page": 0
    },
    [],
    {
      "Title": "Expiration Date",
      "AKA": "",
      "Value": "September 25, 1980",
      "Content": "Expired September 25, 1980",
      "path": "//Document/Sect/P",
      "page": 0
    },
    {
      "Title": "Expiration Date",
      "AKA": "",
      "Value": "September 25, 1980",
      "Content": "Expired September 25, 1980",
      "path": "//Document/Sect/P",
      "page": 0
    },
    {
      "Title": "Expiration Date",
      "AKA": "",
      "Value": "September 25, 1980",
      "Content": "Expired September 25, 1980",
      "path": "//Document/Sect/P",
      "page": 0
    },
    {
      "Title": "Expiration Date",
      "AKA": "",
      "Value": "September 25, 1980",
      "Content": "Expired September 25, 1980",
      "path": "//Document/Sect/P",
      "page": 0
    },
    {
      "Title": "Expiration Date",
      "AKA": "",
      "Value": "September 25, 1980",
      "Content": "Expired September 25, 1980",
      "path": "//Document/Sect/P",
      "page": 0
    },
    {
      "Title": "Expiration Date",
      "AKA": "",
      "Value": "September 25, 1980",
      "Content": "Expired September 25, 1980",
      "path": "//Document/Sect/P",
      "page": 0
    },
    {
      "Title": "Expiration Date",
      "AKA": "",
      "Value": "September 25, 1980",
      "Content": "Expired September 25, 1980",
      "path": "//Document/Sect/P",
      "page": 0
    },
    {
      "Title": "Expiration Date",
      "AKA": "",
      "Value": "September 25, 1980",
      "Content": "Expired September 25, 1980",
      "path": "//Document/Sect/P",
      "page": 0
    }
  ]
}

我只想删除数组中的“[]”。

这是我编写json的方式

{
  "documentId": @{triggerBody()?['Name']},
  "tags": [
    @{if(equals(length(json(body('HTTP').results)),0), null,json(body('HTTP').results)[0])},
    @{if(equals(length(json(body('HTTP_2').results)),0), json(body('HTTP_2').results),json(body('HTTP_2').results)[0])},
    @{json(body('HTTP_3').results)[0]},
    @{json(body('HTTP_4').results)[0]},
    @{json(body('HTTP_5').results)[0]},
    @{json(body('HTTP_6').results)[0]},
    @{json(body('HTTP_7').results)[0]},
    @{json(body('Method_2').results)[0]},
    @{json(body('Method_3').results)[0]},
    @{json(body('Method_4').results)[0]}
  ]
}

如您所见,对象来自不同的 HTTP 请求。有没有其他方法可以在不添加来自另一个 HTTP 请求的 null 或 [] 对象响应的情况下构造 json?

【问题讨论】:

    标签: azure azure-logic-apps


    【解决方案1】:

    考虑到您提供的示例,实现此目的的一种方法是直接使用Replace() 函数从响应中删除“[]”。下面是我使用的表达方式。

    replace(outputs('Compose'),'[],','')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-11-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-09-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多