How to detect the last iteration in a loop?

I would like to add multiple values to the same variable in a loop (separated by a slash) from this JSON data:

image

Currently, I know 2 ways to do that:

1.) Using json_select_many which works perfectly fine for the catalog-number

json_select_object "label-info"
    outputto "CATALOGNUMBER"
    json_select_many "label-info" "catalog-number" " / "
    sayrest
json_unselect_object

and results in the expected
LR-1893008 / LR-1893008
Unfortunately, I don't get this working for the disambiguations

2.) Using json_foreach & json_select in the example for the PUBLISHER where I want to add the disambiguation in parenthesis

outputto "PUBLISHER"
    json_foreach "label-info"
        json_select "label"
        json_select "name"
            sayrest
        json_select "disambiguation"
        ifnot ""
            say "("
            sayrest
            say ")"
            say " / "    # Always add a Space and Slash and Space at the end of the output
        endif
    json_foreach_end

In this case, the PUBLISHER content always ends with a " / ".
Because
a) I don't know an indicator when the last iteration in the loop appears
b) I also don't know how I could increase a counter by +1 for every iteration
and
c) I don't get the max number of iterations (also known as max number of objects/elements) which I could compare to the current iteration

How do you solve this?

i only made one json version script, but maybe if something like this:

can you show the link for the json?

Ahhh I see, thank you very much for that code snippet!
Instead of appending the Slash at the end of the iteration, you add it at the beginning, starting with the second iteration (to avoid the Slash at the very first position).

I have never coded it that way before, but as long as it works :innocent:

Could you also tell me how do you solve the points a) to c) ?