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