Json_select_array_object and json_length

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.

{
	"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:

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

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?

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

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:

`json_select_many_count "artists"

and

`json_select_many_count "artists" "remixer_artist_name"`

would also work.



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

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

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"

Sorry this shouldn't have been in there.

You're right.

The proposed:

`json_select_many_count "artists" "remixer_artist_name"`

or

`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.

OK, understood.

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.

You can scrap the json_length.

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

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

1 Like

This is now included with Mp3tag v3.21b.

1 Like