# Json\_select\_array\_object and json\_length

**URL:** https://community.mp3tag.de/t/json-select-array-object-and-json-length/61598
**Category:** Web Sources Discussion
**Created:** [July 17, 2023, 11:44pm UTC](https://community.mp3tag.de/t/json-select-array-object-and-json-length/61598 "2023-07-17T23:44:46Z")
**Posts on this page:** 9
**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 17, 2023, 11:44pm UTC](https://community.mp3tag.de/t/json-select-array-object-and-json-length/61598/1 "2023-07-17T23:44:46Z")

</div>

Two requests:

1. New `json_select_array_object` fn to get the length of the array where the property matches the `remixer_artist_name` like this:  
`json_select_array_object "artists" "remixer_artist_name" -1 "1"`.  
The above will return `1` from the example JSON as that's all there is for `remixer_artist_name`.

2. New `json_length` fn will return the length of a string or int. So `deadmau5` would return `8` and `1234` would return `4`.

* * *

`json_select_array "artists" -1 "1"` for the below JSON will return `111`.

```auto
{
	"artists": [{
		"artist_id": 26182,
		"actual_artist_name": "deadmau5",
		"artist_type_name": "Artist"
	}, {
		"artist_id": 615803,
		"remixer_artist_name": "Ninajirachi",
		"artist_type_name": "Remixer"
	}, {
		"artist_id": 78642,
		"actual_artist_name": "The Neptunes",
		"artist_type_name": "Artist"
	}]
}

```

I'm using this in my script to get the length of an array by doing the following:

```auto
OutputTo "ALBUMARTIST"
json_select_array "artists" -1 "1" # This basically adds a 1 for every index.
RegexpReplace ".{6,}" "True" # Set the number in this RegexReplace fn to the maximum number of artists before VA and COMPILATION are written
If "True"
Set "ALBUMARTIST"
Say "VA"
OutputTo "COMPILATION"
Say "1"
Else
json_select_many "artists" "name" ", " " & "
SayRest
Endif

```

---

<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 18, 2023, 9:39am UTC](https://community.mp3tag.de/t/json-select-array-object-and-json-length/61598/2 "2023-07-18T09:39:07Z")

</div>

> [@stevehero](#):
>
> New `json_select_array_object` fn to get the length of the array where the property matches the `remixer_artist_name` like this:  
> `json_select_array_object "artists" "remixer_artist_name" -1 "1"`.

I'm not sure about the name and the relevance of the third and fourth parameter. From what you describe, I'd envision something like

`json_select_many_count "artists" "remixer_artist_name"`

What do you think?

> [@stevehero](#):
>
> New `json_length` fn will return the length of a string or int.

Can you give a usage example and where you'd use it in your WS?

---

<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 18, 2023, 6:14pm UTC](https://community.mp3tag.de/t/json-select-array-object-and-json-length/61598/3 "2023-07-18T18:14:26Z")

</div>

> [@Florian](#):
>
> `json_select_many_count "artists" "remixer_artist_name"`

This sounds good. If you can go with that it would be very useful.

I guess if it could count the array length too and not just the nested property, like:

```auto
`json_select_many_count "artists"

```

and

```auto
`json_select_many_count "artists" "remixer_artist_name"`

```

would also work.

* * *

* * *

> [@Florian](#):
>
> Can you give a usage example and where you'd use it in your WS?

Here's the combined fn above also to give you an idea of how I would implement it.

```auto
json_select_many_count "artists" # Here it returns the array length
json_length # Set the number in this RegexReplace fn to the maximum number of artists before VA and COMPILATION are written
IfGreater 6
Set "ALBUMARTIST"
Say "VA"
OutputTo "COMPILATION"
Say "1"
Else
json_select_many "artists" "name" ", " " & "
SayRest
Endif

```

---

<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 18, 2023, 6:44pm UTC](https://community.mp3tag.de/t/json-select-array-object-and-json-length/61598/4 "2023-07-18T18:44:02Z")

</div>

> [@stevehero](#):
>
> ```auto
> json_select_many_count "artists"
> json_length
> IfGreater 6
> 
> ```

Please let me explain how I understand this part and how I'd approach it without using `json_length`. It might be that I misunderstand your intentions here, if so, please correct me.

`json_select_many_count "artists"`  
→ emits the number of elements in the array, e.g., `3` from your earlier example.

`json_length`  
→ according to your initial description computes the string length of the current input `3`, which would be `1`. This is where it doesn't make sense for me.

`IfGreater 6`  
→ only treat as various artists compilation if more than 6 artists are involved. This already could be achieved by omitting the previous call to `json_length`, because the number of artists is already emitted by `json_select_many_count "artists"`

---

<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 18, 2023, 7:08pm UTC](https://community.mp3tag.de/t/json-select-array-object-and-json-length/61598/5 "2023-07-18T19:08:51Z")

</div>

> [@stevehero](#):
>
> `json_length `

Sorry this shouldn't have been in there.

You're right.

The proposed:

```auto
`json_select_many_count "artists" "remixer_artist_name"`

```

or

```auto
`json_select_many_count "artists"

```

would return the array length or the nested array object count.

* * *

`json_length` on the other hand would only get the length of a string or number lets say.

---

<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 18, 2023, 7:12pm UTC](https://community.mp3tag.de/t/json-select-array-object-and-json-length/61598/6 "2023-07-18T19:12:29Z")

</div>

> [@stevehero](#):
>
> would return the array length or the nested array object count.

OK, understood.

> [@stevehero](#):
>
> `json_length` on the other hand would only get the length of a string or number lets say.

Can you describe which string length would be checked there. The one on the current input, e.g. after a `json_select`?

Also, where would you use this specifically? I'm asking because each new function needs maintenance, needs to be tested, needs to be checked for interference with other functions, and needs eventually be ported to macOS.

---

<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 18, 2023, 8:02pm UTC](https://community.mp3tag.de/t/json-select-array-object-and-json-length/61598/7 "2023-07-18T20:02:27Z")

</div>

You can scrap the `json_length`.

I had a usecase for it last night and can't think of it. `long day at work` 🫥

---

<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 18, 2023, 8:03pm UTC](https://community.mp3tag.de/t/json-select-array-object-and-json-length/61598/8 "2023-07-18T20:03:41Z")

</div>

OK, then expect a new build soon — working on it.

---

<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:43pm UTC](https://community.mp3tag.de/t/json-select-array-object-and-json-length/61598/9 "2023-07-19T20:43:00Z")

</div>

This is now included with [Mp3tag v3.21b](https://community.mp3tag.de/t/455).
