Trying to disect a payload object and combine parts into msg.options

I am querying a Sonos node to get my saved favourite radio stations to send to a dashboard dropdown node. From what I have researched, I should be sending it as a msg.options object.
I have located the parts of where my radio stations are stored.
They are stored in payload[0].title, payload[1].title etc. One of the (many) problems is I do not know how long the array is. I can see a number on the debug node but cannot find a corresponding value in the message. I have experimented with substringafter and substringbefore, that did not work. I also experimented with the split node and the string node. FAIL.
I guess that somehow I have to use a function node to read the array, store it, then send as msg.options
Marked here is the array length (but cannot find that number in the message) and one of the stations I need
image

This is the whole debug message:

{"_msgid":"788ab445d2d20e3e","payload":[{"id":"FV:2/10","title":"Capital DANCE","artist":"","album":"","description":"Sonos Radio Station","uri":"x-sonosapi-stream:tunein%3a153035?sid=303&flags=8224&sn=1","artUri":"https://sali.sonos.radio/image?w=60&image=https%3A%2F%2Fcdn-profiles.tunein.com%2Fs309497%2Fimages%2Flogog.jpg%3Ft%3D2&partnerId=tunein","metadata":"<DIDL-Lite xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:upnp="urn:schemas-upnp-org:metadata-1-0/upnp/" xmlns:r="urn:schemas-rinconnetworks-com:metadata-1-0/" xmlns="urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/"><item id="10092020tunein%3a153035" parentID="00020000station:dance" restricted="true"><dc:title>Capital DANCE</dc:title><upnp:class>object.item.audioItem.audioBroadcast</upnp:class><desc id="cdudn" nameSpace="urn:schemas-rinconnetworks-com:metadata-1-0/">SA_RINCON77575_</desc></item></DIDL-Lite>","sid":"303","serviceName":"Sonos Radio","upnpClass":"object.item.audioItem.audioBroadcast","processingType":"stream"},{"id":"FV:2/9","title":"Heart Dance","artist":"","album":"","description":"Sonos Radio Station","uri":"x-sonosapi-stream:tunein%3a95904?sid=303&flags=8224&sn=1","artUri":"https://sali.sonos.radio/image?w=60&image=https%3A%2F%2Fcdn-profiles.tunein.com%2Fs306293%2Fimages%2Flogog.jpg%3Ft%3D156104&partnerId=tunein","metadata":"<DIDL-Lite xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:upnp="urn:schemas-upnp-org:metadata-1-0/upnp/" xmlns:r="urn:schemas-rinconnetworks-com:metadata-1-0/" xmlns="urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/"><item id="10092020tunein%3a95904" parentID="00020000station:dance" restricted="true"><dc:title>Heart Dance</dc:title><upnp:class>object.item.audioItem.audioBroadcast</upnp:class><desc id="cdudn" nameSpace="urn:schemas-rinconnetworks-com:metadata-1-0/">SA_RINCON77575_</desc></item></DIDL-Lite>","sid":"303","serviceName":"Sonos Radio","upnpClass":"object.item.audioItem.audioBroadcast","processingType":"stream"},{"id":"FV:2/3","title":"Heart Essex","artist":"","album":"","description":"Sonos Radio Station","uri":"x-sonosapi-stream:global%3a99524?sid=303&flags=8224&sn=1","artUri":"https://sali.sonos.radio/image?w=60&image=https%3A%2F%2Fherald.musicradio.com%2Fmedia%2F9357ca3a-3ec2-4114-8c45-c2391bc418f4.png&partnerId=global","metadata":"<DIDL-Lite xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:upnp="urn:schemas-upnp-org:metadata-1-0/upnp/" xmlns:r="urn:schemas-rinconnetworks-com:metadata-1-0/" xmlns="urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/"><item id="10092020global%3a99524" parentID="00020000station:heart essex" restricted="true"><dc:title>Heart Essex</dc:title><upnp:class>object.item.audioItem.audioBroadcast</upnp:class><desc id="cdudn" nameSpace="urn:schemas-rinconnetworks-com:metadata-1-0/">SA_RINCON77575_</desc></item></DIDL-Lite>","sid":"303","serviceName":"Sonos Radio","upnpClass":"object.item.audioItem.audioBroadcast","processingType":"stream"},{"id":"FV:2/0","title":"Hit List","artist":"","album":"","description":"Sonos Radio Station","uri":"x-sonosapi-radio:sonos%3a2997?sid=303&flags=8224&sn=1","artUri":"https://sonosradio.imgix.net/placeholders/a78b8e1eb3318dd09f0bb529deed153d_09.png?w=200&auto=format,compress","metadata":"<DIDL-Lite xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:upnp="urn:schemas-upnp-org:metadata-1-0/upnp/" xmlns:r="urn:schemas-rinconnetworks-com:metadata-1-0/" xmlns="urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/"><item id="100c2020sonos%3a2997" parentID="00080004%2fstations%2fen-US%2fUK%2fc2Q6VUs6cG9wLWhpdHM" restricted="true"><dc:title>Hit List</dc:title><upnp:class>object.item.audioItem.audioBroadcast.#list-genre</upnp:class><desc id="cdudn" nameSpace="urn:schemas-rinconnetworks-com:metadata-1-0/">SA_RINCON77575_</desc></item></DIDL-Lite>","sid":"303","serviceName":"Sonos Radio","upnpClass":"object.item.audioItem.audioBroadcast.#list-genre","processingType":"stream"},{"id":"FV:2/8","title":"KISS","artist":"","album":"","description":"Planet Radio Station","uri":"x-sonosapi-stream:pru_svc_ki1?sid=320&flags=32&sn=3","artUri":"http://dtu8ldmaopof3.cloudfront.net/i/b64aHR0cHM6Ly9tZWRpYS5iYXVlcnJhZGlvLmNvbS9pbWFnZS91cGxvYWQvY19jcm9wLGdfY3VzdG9tL3YxNjE4MzE1MDI5L2JyYW5kX21hbmFnZXIvc3RhdGlvbnMvYWNpMmxqaDZ0cHpwdGJ2aXpmeGkucG5n_300.jpg","metadata":"<DIDL-Lite xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:upnp="urn:schemas-upnp-org:metadata-1-0/upnp/" xmlns:r="urn:schemas-rinconnetworks-com:metadata-1-0/" xmlns="urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/"><item id="10090020pru_svc_ki1" parentID="10fe00c4pru_stations" restricted="true"><dc:title>KISS</dc:title><upnp:class>object.item.audioItem.audioBroadcast</upnp:class><desc id="cdudn" nameSpace="urn:schemas-rinconnetworks-com:metadata-1-0/">SA_RINCON81927_X_#Svc81927-0-Token</desc></item></DIDL-Lite>","sid":"320","serviceName":"","upnpClass":"object.item.audioItem.audioBroadcast","processingType":"stream"},{"id":"FV:2/7","title":"KISS DANCE","artist":"","album":"","description":"Planet Radio Station","uri":"x-sonosapi-stream:pru_svc_ki5?sid=320&flags=32&sn=3","artUri":"http://dtu8ldmaopof3.cloudfront.net/i/b64aHR0cHM6Ly9tZWRpYS5iYXVlcnJhZGlvLmNvbS9pbWFnZS91cGxvYWQvY19jcm9wLGdfY3VzdG9tL3YxNjYxMjUyMjkzL2JyYW5kX21hbmFnZXIvc3RhdGlvbnMvcnJ0ZnU2YnBucHZoa3NrNDU5a2suanBn_300.jpg","metadata":"<DIDL-Lite xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:upnp="urn:schemas-upnp-org:metadata-1-0/upnp/" xmlns:r="urn:schemas-rinconnetworks-com:metadata-1-0/" xmlns="urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/"><item id="10090020pru_svc_ki5" parentID="10fe00c4pru_stations" restricted="true"><dc:title>KISS DANCE</dc:title><upnp:class>object.item.audioItem.audioBroadcast</upnp:class><desc id="cdudn" nameSpace="urn:schemas-rinconnetworks-com:metadata-1-0/">SA_RINCON81927_X_#Svc81927-0-Token</desc></item></DIDL-Lite>","sid":"320","serviceName":"","upnpClass":"object.item.audioItem.audioBroadcast","processingType":"stream"},{"id":"FV:2/1","title":"Main Stream","artist":"","album":"","description":"Sonos Radio Station","uri":"x-sonosapi-radio:sonos%3a3014?sid=303&flags=8224&sn=1","artUri":"https://sonosradio.imgix.net/placeholders/04ecd6eaa694770d0d468e371d7ecf50_09.png?w=200&auto=format,compress","metadata":"<DIDL-Lite xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:upnp="urn:schemas-upnp-org:metadata-1-0/upnp/" xmlns:r="urn:schemas-rinconnetworks-com:metadata-1-0/" xmlns="urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/"><item id="100c2020sonos%3a3014" parentID="00080004%2fstations%2fen-US%2fUK%2fc2Q6VUs6cG9wLWhpdHM" restricted="true"><dc:title>Main Stream</dc:title><upnp:class>object.item.audioItem.audioBroadcast.#list-genre</upnp:class><desc id="cdudn" nameSpace="urn:schemas-rinconnetworks-com:metadata-1-0/">SA_RINCON77575_</desc></item></DIDL-Lite>","sid":"303","serviceName":"Sonos Radio","upnpClass":"object.item.audioItem.audioBroadcast.#list-genre","processingType":"stream"},{"id":"FV:2/5","title":"Radio 1","artist":"","album":"","description":"BBC Sounds Station","uri":"x-sonosapi-hls:stations%7eplayable%7e%7ebbc_radio_one%7e%7eurn%3abbc%3aradio%3anetwork%3abbc_radio_one?sid=325&flags=288&sn=2","artUri":"https://sounds.files.bbci.co.uk/3.4.2/networks/bbc_radio_one/colour_450x450.png","metadata":"<DIDL-Lite xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:upnp="urn:schemas-upnp-org:metadata-1-0/upnp/" xmlns:r="urn:schemas-rinconnetworks-com:metadata-1-0/" xmlns="urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/"><item id="10090120stations%7eplayable%7e%7ebbc_radio_one%7e%7eurn%3abbc%3aradio%3anetwork%3abbc_radio_one" parentID="00080000experience%7emodule%7e%7elisten_live%7e%7e" restricted="true"><dc:title>Radio 1</dc:title><upnp:class>object.item.audioItem.audioBroadcast</upnp:class><desc id="cdudn" nameSpace="urn:schemas-rinconnetworks-com:metadata-1-0/">SA_RINCON83207_X_#Svc83207-0-Token</desc></item></DIDL-Lite>","sid":"325","serviceName":"","upnpClass":"object.item.audioItem.audioBroadcast","processingType":"stream"},{"id":"FV:2/6","title":"Radio 1 Dance","artist":"","album":"","description":"BBC Sounds Station","uri":"x-sonosapi-hls:stations%7eplayable%7e%7ebbc_radio_one_dance%7e%7eurn%3abbc%3aradio%3anetwork%3abbc_radio_one_dance?sid=325&flags=288&sn=2","artUri":"https://sounds.files.bbci.co.uk/3.4.2/networks/bbc_radio_one_dance/colour_450x450.png","metadata":"<DIDL-Lite xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:upnp="urn:schemas-upnp-org:metadata-1-0/upnp/" xmlns:r="urn:schemas-rinconnetworks-com:metadata-1-0/" xmlns="urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/"><item id="10090120stations%7eplayable%7e%7ebbc_radio_one_dance%7e%7eurn%3abbc%3aradio%3anetwork%3abbc_radio_one_dance" parentID="00080000experience%7emodule%7e%7elisten_live%7e%7e" restricted="true"><dc:title>Radio 1 Dance</dc:title><upnp:class>object.item.audioItem.audioBroadcast</upnp:class><desc id="cdudn" nameSpace="urn:schemas-rinconnetworks-com:metadata-1-0/">SA_RINCON83207_X_#Svc83207-0-Token</desc></item></DIDL-Lite>","sid":"325","serviceName":"","upnpClass":"object.item.audioItem.audioBroadcast","processingType":"stream"},{"id":"FV:2/4","title":"Radio Essex","artist":"","album":"","description":"Sonos Radio Station","uri":"x-sonosapi-stream:tunein%3a18768?sid=303&flags=8224&sn=1","artUri":"https://sali.sonos.radio/image?w=60&image=https%3A%2F%2Fcdn-radiotime-logos.tunein.com%2Fs86688g.png&partnerId=tunein","metadata":"<DIDL-Lite xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:upnp="urn:schemas-upnp-org:metadata-1-0/upnp/" xmlns:r="urn:schemas-rinconnetworks-com:metadata-1-0/" xmlns="urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/"><item id="10092020tunein%3a18768" parentID="00020000station:radio essex" restricted="true"><dc:title>Radio Essex</dc:title><upnp:class>object.item.audioItem.audioBroadcast</upnp:class><desc id="cdudn" nameSpace="urn:schemas-rinconnetworks-com:metadata-1-0/">SA_RINCON77575_</desc></item></DIDL-Lite>","sid":"303","serviceName":"Sonos Radio","upnpClass":"object.item.audioItem.audioBroadcast","processingType":"stream"},{"id":"FV:2/2","title":"Shake It Off","artist":"","album":"","description":"Sonos Radio Station","uri":"x-sonosapi-radio:sonos%3a155571?sid=303&flags=8224&sn=1","artUri":"https://sonosradio.imgix.net/station-images/c10db51e-0a6c-4cd6-98ec-00b31c1636f5.png?w=200&auto=format,compress","metadata":"<DIDL-Lite xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:upnp="urn:schemas-upnp-org:metadata-1-0/upnp/" xmlns:r="urn:schemas-rinconnetworks-com:metadata-1-0/" xmlns="urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/"><item id="100c2020sonos%3a155571" parentID="00080004%2fstations%2fen-US%2fUK%2fc2Q6VUs6cG9wLWhpdHM" restricted="true"><dc:title>Shake It Off</dc:title><upnp:class>object.item.audioItem.audioBroadcast.#list-genre</upnp:class><desc id="cdudn" nameSpace="urn:schemas-rinconnetworks-com:metadata-1-0/">SA_RINCON77575_</desc></item></DIDL-Lite>","sid":"303","serviceName":"Sonos Radio","upnpClass":"object.item.audioItem.audioBroadcast.#list-genre","processingType":"stream"}]}

You could use a change node with a jsonata expression:

Not sure why you need to know the length of the array.
Keep in mind that the idea of node-red is "low-code", jsonata is quite powerful for these types of operations.

:joy: I was properly overthinking this one. Creating problems where there arent any... I didnt think jsonata would parse the whole object.

1 Like