Consider Array Elements One At A Time

I am using webmerge to create documents.

I have a rule that looks like this (ignore the {$docType} conditional for this question):

enter image description here

And I pass JSON data that looks like this:

{   
    "forms": [
        {
      "formID": 19,
      "formUrl": "https://www.webmerge.me/merge/123456/y3wpgu",
      "fillIns": {
        "retainedAmount": "2000000"
        }
      },
      {
      "formID": 20,
      "formUrl": "https://www.webmerge.me/merge/111111/a2X5yn",
      "fillIns": []
      }
   ]
 }

This works great and will load each form based on the URL provided as needed.

However, if I have two identical forms with differing fillIns, like this:

{   
    "forms": [
        {
      "formID": 19,
      "formUrl": "https://www.webmerge.me/merge/123456/y3wpgu",
      "fillIns": {
        "retainedAmount": "1000000"
                }
        },
      {
      "formID": 19,
      "formUrl": "https://www.webmerge.me/merge/123456/y3wpgu",
      "fillIns": {
        "retainedAmount": "2000000"
        }
      }
   ]
 }

It merges two forms as it should, but each form has both values for retainedAmount, based on the following mapping:

{foreach from=$forms item=_row}{if $_row.formID == 19}{if !empty($_row.fillIns.retainedAmount)}{$_row.fillIns.retainedAmount|number_format}{/if}{/if}{/foreach} 

So the final result for both forms will look like this:

Retained Amount: 10000002000000

The result I want is that the first instance of the form displays

Retained Amount: 1000000

and the second displays

Retained Amount: 2000000

It appears that since the mapping is looping through each element in the array every time, that is why each form is adding both values.

I have been playing with array_shift and array_pop so that the rule will repeat but only consider one element at a time, but I cannot seem to get it to work correctly.

I think I need to get each element into a variable and then reference that variable in the map, but I cannot seem to get it to work. I would show all my attempts, but it will just be ugly, I think.

Lastly, I will never know at which index or how many identical forms with differing fillIns will appear, so I cannot use a key to guide me either.

Since I realize that not everyone has webmerge, a final result via print would be something like this:

FormID = 19 |Retained Amount = 1000000
FormID = 19 |Retained Amount = 2000000