Json_foreach and json_foreach_reverse access counter

The new Beatport JSON doesn't have an identifier for the track numbers and I was wondering how to access the counter when in the json_foreach_* loop.

The reason for this is to output to the TRACK tag, TRACK/TOTALTRACKS.

So the code may look like this (notice the new SayCounter function)

json_foreach_reverse "results" 

OutputTo "TRACKTEMP" # TRACK/TOTALTRACK|TRACKTEMP
SayCounter
Say "/"
SayOutput "TOTALTRACKS"
Say "|"

outputto "TITLETEMP" 
json_select "name"
sayrest
json_select "mix"
ifnot ""
say " ("
sayrest
say ")"
endif
say "|"

OutputTo "TRACKS"
Say "|"

json_foreach_end

# TRACK COUNTER FIX ** DO NOT DELETE
outputto "TITLE"
sayoutput "TITLETEMP"
set "TITLETEMP"
outputto "TRACK"
sayoutput "TRACKTEMP"
set "TRACKTEMP"


@Florian, perhaps there's a way to do this currently?

This is now available as json_foreach_counter with Mp3tag v3.21b with an option parameter for the number of digits padded with leading zeros if necessary.

json_foreach_counter 1
Returns: 1,2,3,4

json_foreach_counter 2
Returns: 01,02,03,04

2 Likes