MQTT Engine doesn't remove tags when JSON array gets shorter

Hi everyone,

I’m using the MQTT Engine module in Ignition to subscribe to a topic that delivers JSON-formatted payloads. The engine correctly creates tag structures from the incoming data, including arrays.

However, I’m running into an issue:
When the length of an array in the JSON payload decreases (e.g., from 3 elements to 2), the tags corresponding to the removed elements are not deleted. They remain in the tag tree with outdated values.

For example:

// Initial payload
{
  "operations": [
    {
      "bom": [
        {"materialId": 1},
        {"materialId": 2},
        {"materialId": 3}
      ]
    }
  ]
}

Then later:

// Updated payload
{
  "operations": [
    {
      "bom": [
        {"materialId": 1},
        {"materialId": 2}
      ]
    }
  ]
}

After this second payload, the tags under:

[MQTT Engine]devices/device1/operations/0/bom/2/materialId

still exist, even though that array element no longer exists in the new message.

Is there a built-in way for MQTT Engine to automatically remove obsolete tags when the array shrinks?
If not, how do you handle this scenario? Should I script a cleanup process using Gateway Timer Scripts or Tag Change Scripts?

Any advice or examples would be greatly appreciated!

Thanks in advance.

I’ve also tried sending "bom": [null, null] in the payload, hoping that would overwrite or remove the previous objects. However, since the elements in bom are expected to be objects, it seems that sending null doesn’t trigger any updates in the tag structure. The tags for previously existing objects remain untouched.

Hello Janikle,

MQTT Engine does not automatically delete Tags from the MQTT Engine provider (unless you restart Engine) so arriving Tags with missing elements (or metrics) as compared to those previously published will not refresh the Tag structures that have already arrived.

They must be deleted in MQTT Engine provider if any changes have occurred at the Edge whether they contain additional elements or fewer.

But you might read through this tutorial as you design your scripts to remove Tags.

and perhaps more specifically for your case:

Daniel