The deezer web source uses for artist names and their roles a json object that looks like that:
{"SNG_CONTRIBUTORS":{"composer":["Riley B. King","Jules Bihari"],"main_artist":["Eric Clapton","B.B. King"],"music publisher":["Power Force Music (BMI)","Careers-BMG Music Publishing, Inc. (BMI)"]}}
I wanted to extract these json data and write it into the tag field INVOLVEDPEOPLE, that has the very similar structure:
Role1:Person1;Role2:Person2;
I hoped that it would be possible with the available json functions to get to
Composer: Riley B. King, Jules Bihari; Main_Artist: Eric Clapton, B.B. King;...
Sadly, I could not find a json-based solution to extract the array names composer, main_artist, music publisher and all the other possible roles. This means that I would have to know in advance, which roles can appear in the object and I would have to write a dedicated script part for every one of them. This is impossible. Instead I would favor a dynamic solution that delivers the names of the available json objects and this way makes it easy to read the named json arrays.
The following new json functions probably could fill this gap:
- a loop to iterate through the json objects: This function could be called
json_foreach_objectin analogy tojson_foreach, that iterates through a json array; - a function to read the name of the current object:
json_select_nameorjson_foreach_namein analogy tojson_foreach_counter.
With these new json functions my script now could simply be:
json_select_object "SNG_CONTRIBUTORS"
json_foreach_object
set "Role"
outputto "Role"
json_select_name
sayrest
json_select_array "%Role%" -1 ", "
outputto "INVOLVEDPEOPLE"
sayoutput "Role"
say ": "
sayrest
say ";"
json_foreach_end
json_unselect_object
I should mention that I actually use a workaround for this issue, that extracts the names of the arrays with a regular expression before the json mode is switched on, and that uses a do while loop to finally build the tag INVOLVEDPEOPLE