# \[F\] bug with json\_foreach

**URL:** https://community.mp3tag.de/t/f-bug-with-json-foreach/16851
**Category:** Fixed Bugs
**Tags:** bug-fixed
**Created:** [April 25, 2015, 11:25am UTC](https://community.mp3tag.de/t/f-bug-with-json-foreach/16851 "2015-04-25T11:25:46Z")
**Posts on this page:** 1
**Showing post:** 3

<div class="post-metadata">

### Author: ![mp3taglover](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/m/7feea3/32.png) [@mp3taglover](https://community.mp3tag.de/u/mp3taglover)
#### Post date: [May 9, 2015, 5:22pm UTC](https://community.mp3tag.de/t/f-bug-with-json-foreach/16851/3 "2015-05-09T17:22:33Z")

</div>

QUOTE (Leftaf @ May 9 2015, 21:08) \<{POST\_SNAPBACK}\>

Hi mp3taglover

fully right we need a

```
do {
    code block to be executed
}
while (condition);

```

does any one has some syntax for us?!

well, there is actually

```
Do ... While S n Execute the command surrounded by the two commands while S occurs on current position. The optional second parameter limits the execution of the loop to maximal n times.
Do
MoveLine 1
While "<td>"
Nesting of Do commands is not allowed.

```

but nesting is not allowed and the thing is you can't use this in json mode, because it's suitable only for NON json mode..

also there is another bug with json\_foreach, you can't just use multiple nested json\_foreach things if you go through some nested array.

e.g.:

```
# Credits per track
json_foreach "tracklist"
    json_select "type_"
    if "track"
        # ARTIST
        outputto "ARTISTTMP"
        json_select_many "artists" "name" ", "
                ifnot ""
            json_foreach "artists"
                json_select "name"
                ifnot ""        
                    say "<name>"
                    sayrest
                    say "</name>"
                endif
                json_select "anv"
                ifnot ""
                    say "<anv>"
                    sayrest
                    say "</anv>"
                endif
                json_select "join"
                ifnot ""
                    say "<join>"
                    sayrest
                    say "</join>"
                endif
            json_foreach_end
        else
            outputto "ARTISTTMP"
            sayoutput "BANDTMP"
        endif
        say "|"    

        outputto "CRTMP"
        json_select_many "extraartists" "name" ", "
        ifnot ""
            json_foreach "extraartists"            
                json_select "name"
                ifnot ""
                    say "<name>"
                sayrest
                    say "</name>"
                endif
                
                json_select "anv"
                ifnot ""
                    say "<anv>"
                    sayrest
                    say "</anv>"
                endif

                json_select "role"
                ifnot ""
                    say "<role>"
                    sayrest
                    say "</role>"
                endif
                
                json_select "tracks"
                ifnot ""
                    say "<tracks>"
                    sayrest
                    say "</tracks>"
                endif
            json_foreach_end
        endif
        say "|"
    endif
json_foreach_end

```

in this case only ARTISTTMP will be filled correctly with artists and CRTMP will be with root extraartists instead of the extraartists nested for each track, it's all because json\_foreach\_end goes to the root of the array after finishing i think instead of just going to the same element which was selected first.

the only workaround i've found is to put another json\_foreach over tracklist again and put there json\_foreach related to CRTMP:

```
# Credits per track
json_foreach "tracklist"
    json_select "type_"
    if "track"
        outputto "CRTMP"
        json_select_many "extraartists" "name" ", "
        ifnot ""
            json_foreach "extraartists"            
                json_select "name"
                ifnot ""
                    say "<name>"
                sayrest
                    say "</name>"
                endif
                
                json_select "anv"
                ifnot ""
                    say "<anv>"
                    sayrest
                    say "</anv>"
                endif

                json_select "role"
                ifnot ""
                    say "<role>"
                    sayrest
                    say "</role>"
                endif
                
                json_select "tracks"
                ifnot ""
                    say "<tracks>"
                    sayrest
                    say "</tracks>"
                endif
            json_foreach_end
        endif
        say "|"
    endif
json_foreach_end

```

there should be either some 'break' function to break out of cycle or jump/goto.

---

_[View the full topic](https://community.mp3tag.de/t/f-bug-with-json-foreach/16851)._
