[F] JSON parse (sub)structure


#1

JSON web scripts missing functionality.
Trying to find out how to parse a substructure. Not possible.
E.g. “life”: {“begin”: 1980, “end”: 2000}
However if the structure would be a single-element array then no issue :slight_smile:
“life”: [{“begin”: 1980, “end”: 2000}]
Florian. Help!!!

Edit: JSON is new so we understand the missing functionality.
How to access json tag from another branch?
Real example. JSON returns one structure with various header info like: current page, total pages, found items, etc.

Now I need to display current page and total pages in the release row.
%Page% | %Pages% | %items% | %preview%
Now the “fun” begins.

  1. It is not possible to select elements of a structure. Let’s say this will be available/fixed soon.
  2. I am parsing a sibling of this structure, i.e. Release array. How can I access the elements of the siblings of current parent array?

I am stuck now…


#2

Hi Victor,

can you point me to an example API where you experience those problems?

Kind regards
Florian


#3

Hi Florian,

  1. You can try this musicbrainz example: search artist.

Trying to extract life-span begin/end values and area (country) name.
“life-span”: {
“ended”: true,
“begin”: “1977”,
“end”: “1995”
},

    "area": {
        "disambiguation": "",
        "iso_3166_3_codes": [],
        "sort-name": "United Kingdom",
        "name": "United Kingdom",
        "id": "8a754a16-0027-3a29-b6d7-2b40ea0481ed",
        "iso_3166_2_codes": [],
        "iso_3166_1_codes": ["GB"]
    },
  1. Adopting official mp3tag discogs.src.
    Search by text “Sultans of Swing”.

     "pagination": {
         "per_page": 50,
         "pages": 2,
         "page": 1,
         "urls": {
             "last": "http://api.discogs.com/database/search?release_title=Sultans+Of+Swing&per_page=50&type=release&page=2",
             "next": "http://api.discogs.com/database/search?release_title=Sultans+Of+Swing&per_page=50&type=release&page=2"
         },
         "items": 84
     },
     "results": [{
    

I want to “access” node “pagination” and its children for each “result” element.

Please let me know if you need additional info.
Kind regards, Victor


#4

Hi Victor,

as already discussed via PM, the new version Mp3tag v2.66 now provides dedicated functions to select complex JSON objects.

Kind regards
Florian


#5

Hi Florian,

Thank you for enhancing JSON functionality. I believe JSON will be involved soon in majority of WS scripts.

  1. I confirm new command json_select_object works very well except one small exception: Complex object does not exist. I apologize for not testing in depth the beta version.
    I tried ifnot “” to not execute nested json_select without luck.

  2. You correctly pointed to store “pagination” element in a temp tag (outputto “tmp”) and then provide it to each result element (sayoutput “tmp”). That works perfectly for [ParserScriptAlbum]=… section but not for [ParserScriptIndex]=… one. Maybe I am wrong but tag commands are irrelevant to Index section.

Could you fix those small issues in the next release(s) please or I am missing some commands?

Kind regards,
Victor


#6

It would be nice if reported bugs (json functionality) are fixed in less time.
It is almost 2 years now without any feedback.
There is no way to know json_select_object found the json object or not. Script is useless in big part of the cases.
Try attached script with different artists (Peter Gabriel, Dire Straits, etc). Pay attention to country name column which is set to artist name in many cases.

MusicBrainz__json__Artist.src (2.64 KB)


JSON: Parse (sub)structure