I have this code:
but is shows the "," after the last name, what is the best way to remove this?
the json is:
I have this code:
but is shows the "," after the last name, what is the best way to remove this?
the json is:
I don't know exactly how to solve this in a Web Source.
The solution would be to check if the last row in the foreach-loop is reached.
Only add the ", "
if this is NOT the last iteration/row in this loop.
Yes but how? maybe the code is better in other way?
Hi,
You could achieve this by
ifoutput "composer"
say ", "
endif
ifnot "0"
json_select "names"
json_select "en"
sayrest
endif
In general, if there was a command to bring the content of a buffer to the "current" one, that would solve many similar issues.
E.g. here, "currentbuffer" is the input buffer populated from WS when consuming the input stream (json or text). "Composer" has a trailing comma.
set "currentbuffer"
outputto "currentbuffer"
sayoutput "composer"
set "composer"
regexpreplace "[,\s]+$" ""
gotochar 1
sayrest
We bring buffer "composer" to the input buffer, we process it there and then move it back (Say command).
I had raised similar issue several years back.
Because of this "missing" functionality I had stopped some heavy WS developments had spent endless days.
Only @Florian could help in this case, if he can anyway.
i cannot get this solution to work, can you give me an hint?
Can you please share your discogs release id?
do you mean the album example in the first post?: 893369
What I wrote initially should work (if collected tag is not empty then add separator to it).
I would like to know the exact source and id you use for your example.
It is not Discogs. Discogs do don't use tag "composers" AFAIK.
The source i use is http://vgmdb.info/
In Json: http://vgmdb.info/album/73784?format=json
the websource:
VGMdb#Search by &Album JSON.src (4.8 KB)
The key is ifoutput "composer" ... say ", " ... endif.
Use below section for Performers/Composers.
We need an ifnot "0" to execute loop only when items exists.
On the Composers section I used a TEMP_composer (single value reset on every iteration) so it is filled once from JSON and then it is added to composer/artist.
I hope it is clear now
# Artist
outputto "artist"
json_foreach "performers"
ifnot "0"
json_select "names"
json_select "en"
ifoutput "artist"
say ", "
endif
sayrest
endif
json_foreach_end
# Composers
json_foreach "composers"
ifnot "0"
json_select "names"
json_select "en"
set "TEMP_composer"
outputto "TEMP_composer"
sayrest
outputto "composer"
ifoutput "composer"
say ", "
endif
sayoutput "TEMP_composer"
outputto "artist"
ifoutput "artist"
say ", "
endif
sayoutput "TEMP_composer"
set "TEMP_composer"
endif
json_foreach_end
Thank you @vkostas it worked very nice, i never thought to do it like this, aim still learning.
By the way, after weeks, i have tried everything, but i cant get the track number to work, only the name, is it asking to much?
VGMdb#Search by &Album JSON.src (5.3 KB)
Unfortunately, Track numbers cannot be generated (yet) when they are not present in the input json.
Please find attached your script amended with all validations so it does not fail (or goes mad) when some nodes are missing in the input json.
Please note the Year extracted from the Release date.
I believe say "" is not needed in WS. It does not change the tag. It does not harm to keep it though,
Thank you for your time, i will learn a lot, you are master at this.
YW.
Please note the Say <separator> approach so you can use it for any multi-value tag.
outputto "<yourTag>"
ifoutput "<yourTag>"
say "<separator>" # add separator to <yourTag>
endif
say ... # add value to <yourTag>
Check this post (JSON Normalize) for a working script for your VGMdb provider.
It adds tracks, totaltracks, discnumber, total discs.
woo that's a lot to take in (learn), thank you.