# Json\_foreach and json\_foreach\_reverse access counter

**URL:** https://community.mp3tag.de/t/json-foreach-and-json-foreach-reverse-access-counter/61578
**Category:** Development
**Created:** [July 16, 2023, 12:14pm UTC](https://community.mp3tag.de/t/json-foreach-and-json-foreach-reverse-access-counter/61578 "2023-07-16T12:14:50Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![stevehero](https://community.mp3tag.de/user_avatar/community.mp3tag.de/stevehero/32/337_2.png) [@stevehero](https://community.mp3tag.de/u/stevehero)
#### Post date: [July 16, 2023, 12:14pm UTC](https://community.mp3tag.de/t/json-foreach-and-json-foreach-reverse-access-counter/61578/1 "2023-07-16T12:14:50Z")

</div>

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)

```auto
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?

---

<div class="post-metadata">

### Author: ![Florian](https://community.mp3tag.de/user_avatar/community.mp3tag.de/florian/32/5759_2.png) [@Florian](https://community.mp3tag.de/u/Florian)
#### Post date: [July 19, 2023, 8:47pm UTC](https://community.mp3tag.de/t/json-foreach-and-json-foreach-reverse-access-counter/61578/2 "2023-07-19T20:47:47Z")

</div>

This is now available as `json_foreach_counter` with [Mp3tag v3.21b](https://community.mp3tag.de/t/455) 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`
