Quote from adrianbrookbank on June 1, 2020, 9:01 pmHey,
I am trying to obtain JSON item to variable.
Example source is of JSON is:
I'm loading this via
LoadJSON "https://itunes.apple.com/search?term=Queen+Break+Free&limit=1" [musicvar]
{
"resultCount":1,
"results": [
{"wrapperType":"track", "kind":"song", "artistId":3296287, "collectionId":1440650428, "trackId":1440651310, "artistName":"Queen", "collectionName":"The Platinum Collection (Greatest Hits I, II & III)", "trackName":"I Want to Break Free", "collectionCensoredName":"The Platinum Collection (Greatest Hits I, II & III)", "trackCensoredName":"I Want to Break Free (Single Remix)", "artistViewUrl":"https://music.apple.com/us/artist/queen/3296287?uo=4", "collectionViewUrl":"https://music.apple.com/us/album/i-want-to-break-free-single-remix/1440650428?i=1440651310&uo=4", "trackViewUrl":"https://music.apple.com/us/album/i-want-to-break-free-single-remix/1440650428?i=1440651310&uo=4",
"previewUrl":"https://audio-ssl.itunes.apple.com/itunes-assets/AudioPreview118/v4/0a/71/30/0a713073-f9eb-12a4-71fc-b407e9720c5f/mzaf_4943513192469202572.plus.aac.p.m4a", "artworkUrl30":"https://is1-ssl.mzstatic.com/image/thumb/Music128/v4/9e/58/3b/9e583b8c-785e-64ee-ce3f-dc365f263861/source/30x30bb.jpg", "artworkUrl60":"https://is1-ssl.mzstatic.com/image/thumb/Music128/v4/9e/58/3b/9e583b8c-785e-64ee-ce3f-dc365f263861/source/60x60bb.jpg", "artworkUrl100":"https://is1-ssl.mzstatic.com/image/thumb/Music128/v4/9e/58/3b/9e583b8c-785e-64ee-ce3f-dc365f263861/source/100x100bb.jpg", "collectionPrice":24.99, "trackPrice":1.29, "releaseDate":"1984-02-27T12:00:00Z", "collectionExplicitness":"notExplicit", "trackExplicitness":"notExplicit", "discCount":3, "discNumber":2, "trackCount":17, "trackNumber":5, "trackTimeMillis":258680, "country":"USA", "currency":"USD", "primaryGenreName":"Rock", "isStreamable":true}]
}
How can I get the 'artworkUrl100' key - into a variable? - could someone help me with the example to achieve this please?
It seems even this [musicvar] variable - I am unable to manipulate (strsearch) etc.
Cheers,
Hey,
I am trying to obtain JSON item to variable.
Example source is of JSON is:
I'm loading this via
LoadJSON "https://itunes.apple.com/search?term=Queen+Break+Free&limit=1" [musicvar]
{
"resultCount":1,
"results": [
{"wrapperType":"track", "kind":"song", "artistId":3296287, "collectionId":1440650428, "trackId":1440651310, "artistName":"Queen", "collectionName":"The Platinum Collection (Greatest Hits I, II & III)", "trackName":"I Want to Break Free", "collectionCensoredName":"The Platinum Collection (Greatest Hits I, II & III)", "trackCensoredName":"I Want to Break Free (Single Remix)", "artistViewUrl":"https://music.apple.com/us/artist/queen/3296287?uo=4", "collectionViewUrl":"https://music.apple.com/us/album/i-want-to-break-free-single-remix/1440650428?i=1440651310&uo=4", "trackViewUrl":"https://music.apple.com/us/album/i-want-to-break-free-single-remix/1440650428?i=1440651310&uo=4",
"previewUrl":"https://audio-ssl.itunes.apple.com/itunes-assets/AudioPreview118/v4/0a/71/30/0a713073-f9eb-12a4-71fc-b407e9720c5f/mzaf_4943513192469202572.plus.aac.p.m4a", "artworkUrl30":"https://is1-ssl.mzstatic.com/image/thumb/Music128/v4/9e/58/3b/9e583b8c-785e-64ee-ce3f-dc365f263861/source/30x30bb.jpg", "artworkUrl60":"https://is1-ssl.mzstatic.com/image/thumb/Music128/v4/9e/58/3b/9e583b8c-785e-64ee-ce3f-dc365f263861/source/60x60bb.jpg", "artworkUrl100":"https://is1-ssl.mzstatic.com/image/thumb/Music128/v4/9e/58/3b/9e583b8c-785e-64ee-ce3f-dc365f263861/source/100x100bb.jpg", "collectionPrice":24.99, "trackPrice":1.29, "releaseDate":"1984-02-27T12:00:00Z", "collectionExplicitness":"notExplicit", "trackExplicitness":"notExplicit", "discCount":3, "discNumber":2, "trackCount":17, "trackNumber":5, "trackTimeMillis":258680, "country":"USA", "currency":"USD", "primaryGenreName":"Rock", "isStreamable":true}]
}
How can I get the 'artworkUrl100' key - into a variable? - could someone help me with the example to achieve this please?
It seems even this [musicvar] variable - I am unable to manipulate (strsearch) etc.
Cheers,
Quote from Gaev on June 1, 2020, 10:21 pm@adrianbrookbank
I could not invoke the LoadJSON command in my Chrome browser due to the following reasons logged in the Console section after invoking Inspect mode ...
- warning about synchronous calls being deprecated
- CORS restrictionsSo, I recreated relevant parts of the result via VisualNEOWeb commands like this ...
... reproduce relevant portions of JSON object CreateEmptyObject [musicvar] SetVar [musicvar('resultCount')] 1 CreateEmptyObject [url] SetVar [url('artworkUrl100')] "https://is1-ssl.mzstatic.com/image/thumb/Music128/v4/9e/58/3b/9e583b8c-785e-64ee-ce3f-dc365f263861/source/100x100bb.jpg" CreateEmptyArray [results] SetVar [results(0)] [url] SetVar [musicvar('results')] [results]If you setup a Container with its content set to [musicvar], you will see the end result of this code
If you were able to load the result in variable [musicvar], here is how you would extract what you asked for ...
... musicvar.results is an array SetVar [resultsArray] [musicvar('results')] ... the first (of one) array items is a json object SetVar [firstArrayItem] [resultsArray(0)] ... extract the value for key of artworkUrl100 Setvar [answer] [firstArrayItem('artworkUrl100')] AlertBox "answer" "artworkUrl100 is<br/>[answer]" ""
Hope this helps.
I could not invoke the LoadJSON command in my Chrome browser due to the following reasons logged in the Console section after invoking Inspect mode ...
- warning about synchronous calls being deprecated
- CORS restrictions
So, I recreated relevant parts of the result via VisualNEOWeb commands like this ...
... reproduce relevant portions of JSON object
CreateEmptyObject [musicvar]
SetVar [musicvar('resultCount')] 1
CreateEmptyObject [url]
SetVar [url('artworkUrl100')] "https://is1-ssl.mzstatic.com/image/thumb/Music128/v4/9e/58/3b/9e583b8c-785e-64ee-ce3f-dc365f263861/source/100x100bb.jpg"
CreateEmptyArray [results]
SetVar [results(0)] [url]
SetVar [musicvar('results')] [results]
If you setup a Container with its content set to [musicvar], you will see the end result of this code
If you were able to load the result in variable [musicvar], here is how you would extract what you asked for ...
... musicvar.results is an array
SetVar [resultsArray] [musicvar('results')]
... the first (of one) array items is a json object
SetVar [firstArrayItem] [resultsArray(0)]
... extract the value for key of artworkUrl100
Setvar [answer] [firstArrayItem('artworkUrl100')]
AlertBox "answer" "artworkUrl100 is<br/>[answer]" ""
Hope this helps.
Quote from adrianbrookbank on June 1, 2020, 10:29 pmGaev,
You're a star, CORS is a nightmare, but working my end.
This works great just tested.
Thank you,
Gaev,
You're a star, CORS is a nightmare, but working my end.
This works great just tested.
Thank you,

Quote from luishp on June 1, 2020, 10:33 pmHi @adrianbrookbank. Each JSON file has its own structure, but once you understand how the data is organized it's very easy to get each data chunk. In this case try this (sample app attached, use right button to download).
LoadJSON "https://itunes.apple.com/search?term=Queen+Break+Free&limit=1" [musicvar] SetVar [type] [musicvar.results(0).wrapperType] SetVar [kind] [musicvar.results(0).kind] SetVar [artistid] [musicvar.results(0).artistId] SetVar [trackname] [musicvar.results(0).trackName] SetVar [artworkurl] [musicvar.results(0).artworkUrl30]Regards.
Hi @adrianbrookbank. Each JSON file has its own structure, but once you understand how the data is organized it's very easy to get each data chunk. In this case try this (sample app attached, use right button to download).
LoadJSON "https://itunes.apple.com/search?term=Queen+Break+Free&limit=1" [musicvar] SetVar [type] [musicvar.results(0).wrapperType] SetVar [kind] [musicvar.results(0).kind] SetVar [artistid] [musicvar.results(0).artistId] SetVar [trackname] [musicvar.results(0).trackName] SetVar [artworkurl] [musicvar.results(0).artworkUrl30]
Regards.
Uploaded files:
Quote from luishp on June 1, 2020, 10:35 pm@adrianbrookbank @gaev you both are too quick for me :)
@adrianbrookbank @gaev you both are too quick for me :)
Quote from adrianbrookbank on June 1, 2020, 10:40 pm@luishp @gaev
Perfect - cheers guys.
Perfect - cheers guys.