# Json question help

**URL:** https://community.mp3tag.de/t/json-question-help/50697
**Category:** Web Sources Discussion
**Created:** [November 4, 2020, 9:11am UTC](https://community.mp3tag.de/t/json-question-help/50697 "2020-11-04T09:11:29Z")
**Posts on this page:** 16
**Page:** 1

<div class="post-metadata">

### Author: ![Romano](https://community.mp3tag.de/user_avatar/community.mp3tag.de/romano/32/7465_2.png) [@Romano](https://community.mp3tag.de/u/Romano)
#### Post date: [November 4, 2020, 9:11am UTC](https://community.mp3tag.de/t/json-question-help/50697/1 "2020-11-04T09:11:29Z")

</div>

I have this code:  
 ![](https://community.mp3tag.de/uploads/default/original/2X/1/1b3cc5e80a918b0c02851cf74c3b72fc2c84147b.png)

but is shows the "," after the last name, what is the best way to remove this?  
 ![](https://community.mp3tag.de/uploads/default/original/2X/3/33e86afd1d4a4869411f279fc61c4aca23416989.png)

the json is:  
 ![](https://community.mp3tag.de/uploads/default/original/2X/4/484bc4aac6efd8ed1fbdb025eee77a43b40ccb98.png)

---

<div class="post-metadata">

### Author: ![LyricsLover](https://community.mp3tag.de/letter_avatar_proxy/v4/letter/l/c6cbf5/32.png) [@LyricsLover](https://community.mp3tag.de/u/LyricsLover)
#### Post date: [November 4, 2020, 11:16am UTC](https://community.mp3tag.de/t/json-question-help/50697/2 "2020-11-04T11:16:36Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Romano](https://community.mp3tag.de/user_avatar/community.mp3tag.de/romano/32/7465_2.png) [@Romano](https://community.mp3tag.de/u/Romano)
#### Post date: [November 4, 2020, 11:21am UTC](https://community.mp3tag.de/t/json-question-help/50697/3 "2020-11-04T11:21:45Z")

</div>

Yes but how? maybe the code is better in other way?

---

<div class="post-metadata">

### Author: ![vkostas](https://community.mp3tag.de/user_avatar/community.mp3tag.de/vkostas/32/227_2.png) [@vkostas](https://community.mp3tag.de/u/vkostas)
#### Post date: [December 4, 2020, 4:17pm UTC](https://community.mp3tag.de/t/json-question-help/50697/4 "2020-12-04T16:17:20Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Romano](https://community.mp3tag.de/user_avatar/community.mp3tag.de/romano/32/7465_2.png) [@Romano](https://community.mp3tag.de/u/Romano)
#### Post date: [December 4, 2020, 8:41pm UTC](https://community.mp3tag.de/t/json-question-help/50697/5 "2020-12-04T20:41:45Z")

</div>

i cannot get this solution to work, can you give me an hint?

---

<div class="post-metadata">

### Author: ![vkostas](https://community.mp3tag.de/user_avatar/community.mp3tag.de/vkostas/32/227_2.png) [@vkostas](https://community.mp3tag.de/u/vkostas)
#### Post date: [December 4, 2020, 11:36pm UTC](https://community.mp3tag.de/t/json-question-help/50697/6 "2020-12-04T23:36:21Z")

</div>

Can you please share your discogs release id?

---

<div class="post-metadata">

### Author: ![Romano](https://community.mp3tag.de/user_avatar/community.mp3tag.de/romano/32/7465_2.png) [@Romano](https://community.mp3tag.de/u/Romano)
#### Post date: [December 5, 2020, 8:35am UTC](https://community.mp3tag.de/t/json-question-help/50697/7 "2020-12-05T08:35:39Z")

</div>

do you mean the album example in the first post?: 893369

---

<div class="post-metadata">

### Author: ![vkostas](https://community.mp3tag.de/user_avatar/community.mp3tag.de/vkostas/32/227_2.png) [@vkostas](https://community.mp3tag.de/u/vkostas)
#### Post date: [December 5, 2020, 1:09pm UTC](https://community.mp3tag.de/t/json-question-help/50697/8 "2020-12-05T13:09:24Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Romano](https://community.mp3tag.de/user_avatar/community.mp3tag.de/romano/32/7465_2.png) [@Romano](https://community.mp3tag.de/u/Romano)
#### Post date: [December 5, 2020, 4:55pm UTC](https://community.mp3tag.de/t/json-question-help/50697/9 "2020-12-05T16:55:45Z")

</div>

The source i use is [http://vgmdb.info/](http://vgmdb.info/)

[http://vgmdb.info/album/73784](http://vgmdb.info/album/73784)

In Json: [http://vgmdb.info/album/73784?format=json](http://vgmdb.info/album/73784?format=json)

the websource:

[VGMdb#Search by &Album JSON.src](https://community.mp3tag.de/uploads/short-url/pZhNc0obnOkUS8vDlIOlb1Af1jL.src) (4.8 KB)

---

<div class="post-metadata">

### Author: ![vkostas](https://community.mp3tag.de/user_avatar/community.mp3tag.de/vkostas/32/227_2.png) [@vkostas](https://community.mp3tag.de/u/vkostas)
#### Post date: [December 5, 2020, 5:30pm UTC](https://community.mp3tag.de/t/json-question-help/50697/10 "2020-12-05T17:30:14Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Romano](https://community.mp3tag.de/user_avatar/community.mp3tag.de/romano/32/7465_2.png) [@Romano](https://community.mp3tag.de/u/Romano)
#### Post date: [December 5, 2020, 6:44pm UTC](https://community.mp3tag.de/t/json-question-help/50697/11 "2020-12-05T18:44:26Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![vkostas](https://community.mp3tag.de/user_avatar/community.mp3tag.de/vkostas/32/227_2.png) [@vkostas](https://community.mp3tag.de/u/vkostas)
#### Post date: [December 5, 2020, 7:35pm UTC](https://community.mp3tag.de/t/json-question-help/50697/12 "2020-12-05T19:35:43Z")

</div>

[VGMdb#Search by &Album JSON.src](https://community.mp3tag.de/uploads/short-url/spd6v0bc4fD5Ce3r8fmBTSL5B8f.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,

---

<div class="post-metadata">

### Author: ![Romano](https://community.mp3tag.de/user_avatar/community.mp3tag.de/romano/32/7465_2.png) [@Romano](https://community.mp3tag.de/u/Romano)
#### Post date: [December 5, 2020, 7:43pm UTC](https://community.mp3tag.de/t/json-question-help/50697/13 "2020-12-05T19:43:25Z")

</div>

Thank you for your time, i will learn a lot, you are master at this.

---

<div class="post-metadata">

### Author: ![vkostas](https://community.mp3tag.de/user_avatar/community.mp3tag.de/vkostas/32/227_2.png) [@vkostas](https://community.mp3tag.de/u/vkostas)
#### Post date: [December 5, 2020, 7:50pm UTC](https://community.mp3tag.de/t/json-question-help/50697/14 "2020-12-05T19:50:52Z")

</div>

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

---

<div class="post-metadata">

### Author: ![vkostas](https://community.mp3tag.de/user_avatar/community.mp3tag.de/vkostas/32/227_2.png) [@vkostas](https://community.mp3tag.de/u/vkostas)
#### Post date: [December 7, 2020, 10:26am UTC](https://community.mp3tag.de/t/json-question-help/50697/15 "2020-12-07T10:26:16Z")

</div>

Check [this post (JSON Normalize)](https://community.mp3tag.de/t/ws-json-normalize-manipulate-json-utility/51062/1) for a working script for your VGMdb provider.  
It adds tracks, totaltracks, discnumber, total discs.

---

<div class="post-metadata">

### Author: ![Romano](https://community.mp3tag.de/user_avatar/community.mp3tag.de/romano/32/7465_2.png) [@Romano](https://community.mp3tag.de/u/Romano)
#### Post date: [December 7, 2020, 11:35am UTC](https://community.mp3tag.de/t/json-question-help/50697/16 "2020-12-07T11:35:35Z")

</div>

woo that's a lot to take in (learn), thank you.
