# Problems selecting JSON Object

**URL:** https://community.mp3tag.de/t/problems-selecting-json-object/18544
**Category:** Web Sources Discussion
**Created:** [December 24, 2016, 6:42pm UTC](https://community.mp3tag.de/t/problems-selecting-json-object/18544 "2016-12-24T18:42:30Z")
**Posts on this page:** 1
**Showing post:** 1

<div class="post-metadata">

### Author: ![Mihawk90](https://community.mp3tag.de/user_avatar/community.mp3tag.de/mihawk90/32/223_2.png) [@Mihawk90](https://community.mp3tag.de/u/Mihawk90)
#### Post date: [December 24, 2016, 6:42pm UTC](https://community.mp3tag.de/t/problems-selecting-json-object/18544/1 "2016-12-24T18:42:30Z")

</div>

Hey there.

Currently trying my hands on a WS Script for [fanart.tv](http://fanart.tv). So far I've been able to get the data from the API to load (yay), but I'm not sure if I'm doing it right. There is no output when I use json\_object, so I don't know if it accessed it, since it also doesn't error out when it _doesn't_ find an object by that name.

But first, here's the current code:

```
# ###################################################################
# Mp3tag Tag Source for FanartTV API
#
# Search by MusicBrainz Release-Group ID
#
# This file should be stored in your tag sources sources directory
# %APPDATA%\Mp3tag\data\sources
# and requires Mp3tag v2.64 or above.
#
# ###################################################################

[Name]=Fanart.tv
[BasedOn]=www.fanart.tv
# Append personal API Key, more info about them here:
# <a href="https://fanart.tv/2015/01/personal-api-keys/" target="_blank">https://fanart.tv/2015/01/personal-api-keys/</a>
[IndexUrl]=http://webservice.fanart.tv/v3/music/albums/%s?api_key=738e7602362418fda8158f44fb12e6df&client_key=
[IndexFormat]=%_url%|%preview%
[SearchBy]=%MUSICBRAINZ RELEASE GROUP ID%

[ParserScriptIndex]=...
# ###################################################################
# I N D E X
# ###################################################################
debug "on" "C:\Users\Tarulia\AppData\Roaming\Mp3tag\debug_fanarttv.txt" "5"

json "ON"

# API returns 404 on error, no need to read out error message as Mp3tag errors out on 404

# get the actual image
json_select_object "albums"
    json_select_object "8f4d4f05-36ed-3c81-86a7-aae2a03b1520"
        json_select_array "albumcover" 0
            json_select "url"
                outputto "coverurl"
                sayrest

```

And the Debug Output (note that I commented out the select\_array and following, see below)

```
Total output to process:
------------------------------------------------------------
{
    "name": "3 Doors Down",
    "mbid_id": "2386cd66-e923-4e8e-bf14-2eebe2e9b973",
    "albums": {
        "8f4d4f05-36ed-3c81-86a7-aae2a03b1520": {
            "cdart": [
                {
                    "id": "8618",
                    "url": "http://assets.fanart.tv/fanart/music/2386cd66-e923-4e8e-bf14-2eebe2e9b973/cdart/away-from-the-sun-4e484652567b2.png",
                    "likes": "2",
                    "disc": "1",
                    "size": "1000"
                },
                {
                    "id": "61074",
                    "url": "http://assets.fanart.tv/fanart/music/2386cd66-e923-4e8e-bf14-2eebe2e9b973/cdart/away-from-the-sun-509e55644d26d.png",
                    "likes": "0",
                    "disc": "1",
                    "size": "1000"
                }
            ],
            "albumcover": [
                {
                    "id": "190047",
                    "url": "http://assets.fanart.tv/fanart/music/2386cd66-e923-4e8e-bf14-2eebe2e9b973/albumcover/away-from-the-sun-56cc1174dfda4.jpg",
                    "likes": "2"
                }
            ]
        }
    }
}
------------------------------------------------------------

Output : ><

Line and position:
{
^

------------------------------------------------------------

Script-Line : 26
Command : json
Parameter 1 : >ON<

Output : ><

Line and position:
{
^

------------------------------------------------------------

Script-Line : 31
Command : json_select_object
Parameter 1 : >albums<

Output : ><

Line and position:

^

------------------------------------------------------------

Script-Line : 32
Command : json_select_object
Parameter 1 : >8f4d4f05-36ed-3c81-86a7-aae2a03b1520<

Output : ><

Line and position:

^

------------------------------------------------------------

Total output:
 output["CurrentUrl"]= "http://webservice.fanart.tv/v3/music/albums/8f4d4f05-36ed-3c81-86a7-aae2a03b1520?api_key=738e7602362418fda8158f44fb12e6df&client_key="
 output["Output"]= ""
 output["Error"]= "<OK>"

```

Note that I hardcoded the second json\_select\_object for testing.

Now I have multiple problems:

**1.** When I use ParserScriptAlbum instead of ParserScriptIndex, no log file is created. At all. Also I have no idea what's the difference really, but I assume I actually need the ParserScriptAlbum since it's probably showing the result of the selected album?

**2.** When I use the script like that, there is no log file created, at all, unless I comment out the json\_select\_array and the following lines.

**3.** In the real world I can't actually hardcode the MBID into the json\_select\_object function, but I haven't been able to use the actual ID in any way. I tried using %MUSICBRAINZ RELEASE GROUP ID% and %s both with and without quotes, but according to the debug output the value isn't used. Is there even a way of using that variable? If not, well.. I got a problem 🙂 Can I use json\_foreach on the albums object or does it not work on objects, but only on arrays?

**4.** Is it normal that there is no Output when selecting an object? I have no idea if the selection actually works or not. Is there a way to get a serialized version of the selected object into the output?

Hope someone can give me a hint and/or get me on the right track from where I can continue on my own 🙂

Thanks in advance

---

_[View the full topic](https://community.mp3tag.de/t/problems-selecting-json-object/18544)._
