No internet connection
  1. Home
  2. Questions

Remove JSON Array Object and properties within it

By @matty
    2022-11-23 20:26:22.204Z2022-11-23 23:46:04.810Z

    I have an JSON array and I would like to remove one of the objects. The path of the array is attachments[1]. Using the update json action with the remove path operation doesn't work.

    I can remove the individual properties within the array object using the remove path operation but when I do this the empty curly braces {} still remain for the object.

    Is there a way to remove an array object entirely?

    {
    "attachments": [
    {
    "type": "%AttachmentTypeOther%",
    "name": "%AttachmentNameOther%",
    "content": "%AttachmentContentOther%"
    },
    {
    "type": "%AttachmentTypeBOL%",
    "name": "%AttachmentNameBOL%",
    "content": "%AttachmentContentBOL%"
    }
    ]}

    • 2 replies
    1. I
      isedwinr @isedwinr
        2022-11-24 06:40:59.628Z

        Hi,
        It's not the cleanest of solutions but RegEx Replace or Search and Replace for the last part maybe is an option?
        I don't know much about Json so maybe this is not suitable at all

        Edwin

        1. D
          In reply tomatty:
          Daniel Horton @daniel.horton
            2022-11-24 10:52:28.072Z

            Hi Matty,

            We have found the issue and resolved this in our next pre-release.

            For clarity when you use the Remove Path functionality and supply an array index position it automatically updates the array index. This means that if you wish to remove items 2 and 3 you would need to call position 1 twice in your Remove Path.

            With the following example if we wished to remove topping[1] and topping [2] we would do it like this:

            {
            	"id": "0001",
            	"type": "donut",
            	"name": "Cake",
            	"ppu": 0.55,
            	"batters":
            		{
            			"batter":
            				[
            					{ "id": "1001", "type": "Regular" },
            					{ "id": "1002", "type": "Chocolate" },
            					{ "id": "1003", "type": "Blueberry" },
            					{ "id": "1004", "type": "Devil's Food" }
            				]
            		},
            	"topping":
            		[
            			{ "id": "5001", "type": "None" },
            			{ "id": "5002", "type": "Glazed" },
            			{ "id": "5005", "type": "Sugar" },
            			{ "id": "5007", "type": "Powdered Sugar" },
            			{ "id": "5006", "type": "Chocolate with Sprinkles" },
            			{ "id": "5003", "type": "Chocolate" },
            			{ "id": "5004", "type": "Maple" }
            		]
            }