# Selection of a nested array is not working

**URL:** https://community.mp3tag.de/t/selection-of-a-nested-array-is-not-working/47777
**Category:** Web Sources Discussion
**Created:** [February 4, 2020, 4:41pm UTC](https://community.mp3tag.de/t/selection-of-a-nested-array-is-not-working/47777 "2020-02-04T16:41:28Z")
**Posts on this page:** 3
**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: [February 4, 2020, 4:41pm UTC](https://community.mp3tag.de/t/selection-of-a-nested-array-is-not-working/47777/1 "2020-02-04T16:41:28Z")

</div>

```auto
[Name]=beatport.com [v5.0 by stevehero™] (◣_◢)
[BasedOn]=https://www.beatport.com
[IndexUrl]=https://www.beatport.com/search/releases?q=%s&per-page=25&sort=release-desc
[AlbumUrl]=
[WordSeparator]=+
[IndexFormat]=% ↓ ID (◣_◢)™%|% ↓ RELEASE%|% ↓ ARTIST/S%|%_URL%
[Encoding]=url-utf-8
#:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::#
[ParserScriptIndex]=...
findline "<!DOCTYPE html>"
findinline "<!DOCTYPE html>"
joinuntil "</html>"
replace "|" "$verticalBar()"
regexpreplace "(?i).*?window\.Playables\s*?=\s*?(\{.+);.*?window\.Sliders\s+=\s+\[.*" "$1"
json "ON" "current"
json_foreach "releases"
json_select "id" # ID
sayrest
say "|"
json_select "name" # RELEASES
sayrest
say "|"
json_select_many "artists" "name" " ● " # ARTIST(S)
sayrest
say "|"
say "https://www.beatport.com/release/" # PREVIEW
json_select "slug"
sayrest
json_select "id"
say "/"
sayrest
saynewline
json_foreach_end
#:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::#
[ParserScriptAlbum]=...
# START JSON PARSING
gotoline 5
findline "<!DOCTYPE html>"
findinline "<!DOCTYPE html>"
joinuntil "</html>"
replace "|" "$verticalBar()"
regexpreplace "(?i).*?window\.Playables\s*?=\s*?(\{.+);.*?window\.Sliders\s+=\s+\[.*" "$1"
regexpreplace "\"tracks\": ?\[\s*\]\," "" # Remove empty tracks array
json "ON" "current"

json_select_array "releases" 1

# THERE'S A PROBLEM WITH THIS SELECTING AN ARRAY AND RETURNING THE TOTAL TRACK COUNT
outputto "TOTALTRACKS"
json_foreach "tracks"
sayrest
json_foreach_end

json_unselect_object # Deselect releases
json_unselect_object # Deselect tracks

```

The above outputs `0` to the `TOTALTRACKS` field when AFAIK should count the length of the arrray.

Perhaps it's something I'm doing here.

[Here's a similar issue](https://community.mp3tag.de/t/trouble-with-selecting-the-first-array-element-using-json-select-array/47371) that was resolved. Perhaps it's something on mp3tags' end @Florian ?

I'm removing empty arrays beforehand with:

```auto
regexpreplace "\"tracks\": ?\[\s*\]\," "" # Remove empty tracks array

```

so all I'm left with is the correct one but so far I've not been able to get this working.

---

<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: [February 5, 2020, 9:24am UTC](https://community.mp3tag.de/t/selection-of-a-nested-array-is-not-working/47777/2 "2020-02-05T09:24:36Z")

</div>

It would be helpful if you could also post steps to reproduce with your questions. I've tried several sample releases as input which all didn't have `tracks` under `releases` when running the script.

---

<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: [February 5, 2020, 2:53pm UTC](https://community.mp3tag.de/t/selection-of-a-nested-array-is-not-working/47777/3 "2020-02-05T14:53:32Z")

</div>

Sometimes, (_all the time_) I'm a numbnuts. I took for granted that the `track` items were under the `releases` but they are their own array mixed with non-release tracks.

```auto
json_foreach "tracks"
json_select "component"
if "Release Track Listing"

outputto "BEATPORT_TRACK_ID"
json_select "id"
sayrest
say "|"

outputto "TRACKS"
sayrest
say "|"

endif
json_foreach_end

```
