Home > Software design >  Xquery How to get the name of the song where the available_markets contains more elements than 2
Xquery How to get the name of the song where the available_markets contains more elements than 2

Time:12-06

I have a JSON file with information about 100 Spotify artist. I am trying to get the name of the songs where the "availabla_markets" contains more elements than 2. Example:

{
"href": "https://api.spotify.com/v1/playlists/37i9dQZF1DX2RxBh64BHjQ/tracks?offset=0&limit=100&additional_types=track",
"items": [
    {
        "added_at": "2021-11-29T23:29:54Z",
        "added_by": {
            "external_urls": {
                "spotify": "https://open.spotify.com/user/"
            },
            "href": "https://api.spotify.com/v1/users/",
            "id": "",
            "type": "user",
            "uri": "spotify:user:"
        },
        "is_local": false,
        "primary_color": null,
        "track": {
            "album": {
                "album_type": "single",
                "artists": [
                    {
                        "external_urls": {
                            "spotify": "https://open.spotify.com/artist/0Njy6yR9LykNKYg9yE23QN"
                        },
                        "href": "https://api.spotify.com/v1/artists/0Njy6yR9LykNKYg9yE23QN",
                        "id": "0Njy6yR9LykNKYg9yE23QN",
                        "name": "Nardo Wick",
                        "type": "artist",
                        "uri": "spotify:artist:0Njy6yR9LykNKYg9yE23QN"
                    }
                ],
                "available_markets": [
                    "AD",
                    "AE"
                ],
                "external_urls": {
                    "spotify": "https://open.spotify.com/album/6SEeNB2xGW1kmysKSvWYqC"
                },
                "href": "https://api.spotify.com/v1/albums/6SEeNB2xGW1kmysKSvWYqC",
                "id": "6SEeNB2xGW1kmysKSvWYqC",
                "name": "Me or Sum (feat. Future & Lil Baby)",
            },
            "artists": [
                {
                    "external_urls": {
                        "spotify": "https://open.spotify.com/artist/0Njy6yR9LykNKYg9yE23QN"
                    },
                    "name": "Nardo Wick",
                }
            ],
            "available_markets": [
                "AD",
                "AE",
                "AG",
                "AL",
            ],
            "disc_number": 1,
            "duration_ms": 225664,
            "external_urls": {
                "spotify": "https://open.spotify.com/track/1qlh1WxuWilyIWRwdsKMuJ"
            },

            "name": "Me or Sum (feat. Future & Lil Baby)",
        },
    }
}

How can I return the name of the songs(eg:"Me or Sum (feat. Future & Lil Baby)") where the "available_markets" contains more elements than 2 using Xquery?

CodePudding user response:

json-doc('xxx')?items?*?track[count(?available_markets?*) gt 2]?name
  • Related