Home > Back-end >  How can i remove empty object in an array in Azure Logic apps
How can i remove empty object in an array in Azure Logic apps

Time:10-14

I just want to remove the empty object in an array before sending it to another HTTP request

  "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
    }
  ]
}

I just want to remove '[]' in the array.

Here's how i compose the 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]}
  ]
}

As you can see, objects came from different HTTP request. are there any other way to construct the json without adding the null or [] object response from another HTTP request?

CodePudding user response:

Considering the sample that you have provided, One way to achieve this that you can directly use Replace() function to remove "[]" from your response. Below is the expression I used.

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

enter image description here

  • Related