Question: Suppose the following JSON object was stored as string that I have also done a JSON.parse() on in javascript. (you do not really need to

Suppose the following JSON object was stored as string that I have also done a JSON.parse() on in javascript. (you do not really need to look at it before seeing the question at the bottom)

___________________________________________________________________

{ "tracks" : { "href" : "https://api.spotify.com/v1/search?query=swalla&type=track&market=US&offset=0&limit=20", "items" : [ { "album" : { "album_type" : "single", "artists" : [ { "external_urls" : { "spotify" : "https://open.spotify.com/artist/07YZf4WDAMNwqr4jfgOZ8y" }, "href" : "https://api.spotify.com/v1/artists/07YZf4WDAMNwqr4jfgOZ8y", "id" : "07YZf4WDAMNwqr4jfgOZ8y", "name" : "Jason Derulo", "type" : "artist", "uri" : "spotify:artist:07YZf4WDAMNwqr4jfgOZ8y" }, { "external_urls" : { "spotify" : "https://open.spotify.com/artist/0hCNtLu0JehylgoiP8L4Gh" }, "href" : "https://api.spotify.com/v1/artists/0hCNtLu0JehylgoiP8L4Gh", "id" : "0hCNtLu0JehylgoiP8L4Gh", "name" : "Nicki Minaj", "type" : "artist", "uri" : "spotify:artist:0hCNtLu0JehylgoiP8L4Gh" }, { "external_urls" : { "spotify" : "https://open.spotify.com/artist/7c0XG5cIJTrrAgEC3ULPiq" }, "href" : "https://api.spotify.com/v1/artists/7c0XG5cIJTrrAgEC3ULPiq", "id" : "7c0XG5cIJTrrAgEC3ULPiq", "name" : "Ty Dolla $ign", "type" : "artist", "uri" : "spotify:artist:7c0XG5cIJTrrAgEC3ULPiq" } ], "available_markets" : [ "AD", "AR", "AT", "AU", "BE", "BG", "BO", "BR", "CA", "CH", "CL", "CO", "CR", "CY", "CZ", "DE", "DK", "DO", "EC", "EE", "ES", "FI", "FR", "GB", "GR", "GT", "HK", "HN", "HU", "ID", "IE", "IS", "IT", "JP", "LI", "LT", "LU", "LV", "MC", "MT", "MX", "MY", "NI", "NL", "NO", "NZ", "PA", "PE", "PH", "PL", "PT", "PY", "SE", "SG", "SK", "SV", "TH", "TR", "TW", "US", "UY", "VN" ], "external_urls" : { "spotify" : "https://open.spotify.com/album/2e5CxfyEwBW115beiwh7Mc" }, "href" : "https://api.spotify.com/v1/albums/2e5CxfyEwBW115beiwh7Mc", "id" : "2e5CxfyEwBW115beiwh7Mc", "images" : [ { "height" : 640, "url" : "https://i.scdn.co/image/87d0b1856d2c2ce55fdb4c8129e47a6df6f33aff", "width" : 640 }, { "height" : 300, "url" : "https://i.scdn.co/image/8662260c958cbc63a0f0c671cc95de5bf14f59f2", "width" : 300 }, { "height" : 64, "url" : "https://i.scdn.co/image/2800e9f3f5aadf99620ef196b0d94e602128539f", "width" : 64 } ], "name" : "Swalla (feat. Nicki Minaj & Ty Dolla $ign)", "type" : "album", "uri" : "spotify:album:2e5CxfyEwBW115beiwh7Mc" }, "artists" : [ { "external_urls" : { "spotify" : "https://open.spotify.com/artist/07YZf4WDAMNwqr4jfgOZ8y" }, "href" : "https://api.spotify.com/v1/artists/07YZf4WDAMNwqr4jfgOZ8y", "id" : "07YZf4WDAMNwqr4jfgOZ8y", "name" : "Jason Derulo", "type" : "artist", "uri" : "spotify:artist:07YZf4WDAMNwqr4jfgOZ8y" }, { "external_urls" : { "spotify" : "https://open.spotify.com/artist/0hCNtLu0JehylgoiP8L4Gh" }, "href" : "https://api.spotify.com/v1/artists/0hCNtLu0JehylgoiP8L4Gh", "id" : "0hCNtLu0JehylgoiP8L4Gh", "name" : "Nicki Minaj", "type" : "artist", "uri" : "spotify:artist:0hCNtLu0JehylgoiP8L4Gh" }, { "external_urls" : { "spotify" : "https://open.spotify.com/artist/7c0XG5cIJTrrAgEC3ULPiq" }, "href" : "https://api.spotify.com/v1/artists/7c0XG5cIJTrrAgEC3ULPiq", "id" : "7c0XG5cIJTrrAgEC3ULPiq", "name" : "Ty Dolla $ign", "type" : "artist", "uri" : "spotify:artist:7c0XG5cIJTrrAgEC3ULPiq" } ], "available_markets" : [ "AD", "AR", "AT", "AU", "BE", "BG", "BO", "BR", "CA", "CH", "CL", "CO", "CR", "CY", "CZ", "DE", "DK", "DO", "EC", "EE", "ES", "FI", "FR", "GB", "GR", "GT", "HK", "HN", "HU", "ID", "IE", "IS", "IT", "JP", "LI", "LT", "LU", "LV", "MC", "MT", "MX", "MY", "NI", "NL", "NO", "NZ", "PA", "PE", "PH", "PL", "PT", "PY", "SE", "SG", "SK", "SV", "TH", "TR", "TW", "US", "UY", "VN" ], "disc_number" : 1, "duration_ms" : 216408, "explicit" : true, "external_ids" : { "isrc" : "USWB11700237" }, "external_urls" : { "spotify" : "https://open.spotify.com/track/6kex4EBAj0WHXDKZMEJaaF" }, "href" : "https://api.spotify.com/v1/tracks/6kex4EBAj0WHXDKZMEJaaF", "id" : "6kex4EBAj0WHXDKZMEJaaF", "name" : "Swalla (feat. Nicki Minaj & Ty Dolla $ign)", "popularity" : 87, "preview_url" : "https://p.scdn.co/mp3-preview/9aa4e0500aae8b33d04f031c454688890ab06468?cid=8897482848704f2a8f8d7c79726a70d4", "track_number" : 1, "type" : "track", "uri" : "spotify:track:6kex4EBAj0WHXDKZMEJaaF"

__________________________________________________________________________

What code can I write to always just extract the string following this sequence of characters -> "type" : "track", "uri" :

In this case I want to extract the string "spotify:track:6kex4EBAj0WHXDKZMEJaaF" seen at the end of that block, but the parsed JSON string will not always be in this order and might not be in the same position.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!