I spawned in one pig, and ran the following commands as a test of adding/remove NBT data, specifically modifiers on mobs:
/data merge entity @e[limit=1,type=minecraft:pig] {Attributes:[{Name:"generic.armor",Modifiers:[{UUIDMost:4321,UUIDLeast:1234,Amount:1.0d,Operation:0,Name:"test_armor"}]}]}
This is to add a modifier of 1 extra armor to a pig.
I tried the following to remove said Modifier, but none worked. (note, the 4th entry in the list of attributes is the base armor attribute, so it is not arbitrary)
/data remove entity @e[limit=1,type=minecraft:pig] Attributes[3].Modifiers
/data remove entity @e[limit=1,type=minecraft:pig] Attributes[3].Modifiers[0]
/data remove entity @e[limit=1,type=minecraft:pig] Attributes[3]
None of these had any effect on updating or removing the Modifier. The only possible work around I have found is modifying the values using a merge that either knows the exact index (not really efficient if in command blocks / function file), or using a pair of the UUIDs and Name to set the amount to 0 (Also not what I would like to do, as that would mess with UUID unique pairing).
The expected outcome is that just the modifier will be removed from the NBT data for the armor attribute.
Related issues
Comments


There is only one pig. I had it specified before, but it was removed due to being erroneous for system (which I get).
But the world I am testing on is super flat void. There is only one pig.

To make it easier, I copied the entity info of the pig so it can be summoned for others to confirm the bug.
/summon minecraft:pig -3.28 4.00 0.51 {HurtByTimestamp: 0, Attributes: [{Base: 10.0d, Name: "generic.maxHealth"}, {Base: 0.0d, Name: "generic.knockbackResistance"}, {Base: 0.25d, Name: "generic.movementSpeed"}, {Base: 0.0d, Modifiers: [{UUIDMost: 4321L, UUIDLeast: 1234L, Amount: 1.0d, Operation: 0, Name: "test_armor"}], Name: "generic.armor"}, {Base: 0.0d, Name: "generic.armorToughness"}, {Base: 16.0d, Modifiers: [{UUIDMost: -6091966862844081663L, UUIDLeast: -8668195134178061998L, Amount: -0.07601574596740644d, Operation: 1, Name: "Random spawn bonus"}], Name: "generic.followRange"}], Invulnerable: 0b, FallFlying: 0b, ForcedAge: 0, PortalCooldown: 0, AbsorptionAmount: 0.0f, Saddle: 0b, FallDistance: 0.0f, InLove: 0, DeathTime: 0s, HandDropChances: [0.085f, 0.085f], PersistenceRequired: 0b, Age: 0, Motion: [0.0d, -0.0784000015258789d, 0.0d], Leashed: 0b, Health: 10.0f, LeftHanded: 0b, Air: 300s, OnGround: 1b, Rotation: [96.87854f, -40.0f], HandItems: [{}, {}], ArmorDropChances: [0.085f, 0.085f, 0.085f, 0.085f], Fire: -1s, ArmorItems: [{}, {}, {}, {}], CanPickUpLoot: 0b, HurtTime: 0s}
After summoning, try using the remove commands in the original bug report. There will be no change in the pig's armor modifiers.

Just ran across this bug when playing with a buddy on 1.15.2
We found that not only is deleting impossible, but when I try to merge the array it simply adds the new objects into the array, and we found that when you try to use "data set" on an individual field in the modifier object, such as UUIDLeast or UUIDMost, you end up duplicating the entire modifier, one with the old data and one with the new data. We tested this with villagers, horses, and pigs, and had no luck.
We couldn't delete the modifier. We couldn't "set" the value of the array to empty. We couldn't delete the Modifiers array completely. We couldn't delete the attribute object, and we couldn't empty the Attributes array. It seems once there's a value in the Modifiers array, it's permanent and locks up any attempt to remove its parent objects as well. We were able to modify individual field values within the Attribute that had the modifier but that's about it.

Just found what I think might be a related bug. When attempting to use /data set entity, to apply the value {id:leather_horse_armor,Count:1} to ArmorItems[2] on a horse, it fails.
Also failed when I tried to set the value of ArmorItems to a 4-item array with the leather armor at index 2, it still failed.
So where we're at now, the data tag fails to modify ArmorItems, and Attributes, but succeeds with the Villager's Orders.Recipes array. My first thought was it was simply failing on all arrays but since I can mess with Orders.Recipes that doesn't seem to be the case. At this point, it seems that any array object at the root level is failing to be modified properly, but arrays further down the tree are working more or less OK? Except Modifiers, but that's encased in an array at the root level itself, so I think the problem is happening before the NBT data command even reaches the Modifiers item.
All of this being said, I can set the value of the ArmorItem field, not the ArmorItems array, and apply the horse armor just fine. So once again I'm led to believe somehow the NBT DataCommands class has some kind of issue with arrays.
Can confirm in 20w51a.
Can confirm in 21w06a.

Can confirm in 1.21.4 Pre-Release 1
Try specifying
sort=nearest
in the selector and standing nearby the pig. It may target other ones.