Get array (over 30 entries) into msg.payload

Hi!

Would really like some help on this one. I am getting array of over 30 items, and would like to read specific paths and write it all to single msg.payload that would look like this: msg.payload = (name1, name2, name3).

Values in the array are stored under here:

msg.payload[X].title - where X is a number from 0 to 31.

I have attached the screenshot so you could see what I see.

image

Any help on how to achieve this would be much appreciated.

Thank you!

This takes about 10 seconds in JSONata.

Use a change node, set the option to J: (for JSONata)
enter

payload.title

This will give you an array of the titles.

thank you- like this? it doesn’t seem to produce desired output…

image

edit:

my bad - I have now used it from msg.payload and it does indeed lists the title only, still in array.

How could I take this array and have it output as single msg.payload with this schema: (name1, name2, name3, …)

image

Thank you

got it! I have used split and join nodes to combine it into the below:

Thank you!

I was not entirely sure what you wanted from your output (a set, an array, a concatenated string?) and I don’t have your JSON data to work with, so it was a bit of a guess. It helps in these situations if you could copy the msg object from the debug window (hover over the window and a small menu appears…) and paste this in a format block in your post - that means that anyone can then easily copy the real JSON data to work with. This is particularly useful for working with JSONata expressions.

Yes, the change node should be to ‘set’ the ‘msgpayload to the value of the JSONata expression.

If you just want to concatenate the string values of each title, with a ", " for separation, then you can do this in one go with the following JSONata expression. No need for split and join nodes.

$reduce(payload.title, function($acc, $val){$acc & ", " & $val})

thank you, that single line indeed worked!

I made an error thinking that separation should be " , " - it should be ", " - I have achieved this by amending your code slightly:

$reduce(payload.title, function($acc, $val){$acc & '","' & $val})

I have side question if I may - I am passing this output into call service node to set input_select list. This looks like its working fine BUT in fact - quotation marks are literally written as qoute:

this image - three playlists show fine, this is the output of what was sent to call service node.
image

but in fact input_select list looks like this - it takes quotation marks and ‘writes them out’.

image

image

This is the snippet of the object from debug note (forum wouldn’t accept it in full).

Thank you @Biscuit - I should have pasted this in my OP.

{"_msgid":"ae16da61858b499b","payload":[{"id":"FV:2/72","title":"AWOLNATION","artist":"","album":"","description":"Artist","uri":"","artUri":"https://i.scdn.co/image/ab6761610000e5eb5d42e15eb8c8297112fd26ba","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="10052064spotify%3aartist%3a4njdEjTnLfcGImKZu1iSrz" parentID="10052064spotify%3aartist%3a4njdEjTnLfcGImKZu1iSrz" restricted="true"><dc:title>AWOLNATION</dc:title><upnp:class>object.container.person.musicArtist.#albumsList</upnp:class><desc id="cdudn" nameSpace="urn:schemas-rinconnetworks-com:metadata-1-0/">SA_RINCON2311_X_#Svc2311-7fc72ff3-Token</desc></item></DIDL-Lite>","sid":"","serviceName":"","upnpClass":"object.container.person.musicArtist.#albumsList","processingType":"queue"},{"id":"FV:2/66","title":"Back To Back Sounds","artist":"","album":"","description":"From BBC Sounds","uri":"","artUri":"https://ichef.bbci.co.uk/images/ic/640x640/p0bb4dc9.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="10fe0064music%7emodule%7e%7emusic_page_curations%7e%7e" parentID="10fe0064music%7emodule%7e%7emusic_page_curations%7e%7e" restricted="true"><dc:title>Back To Back Sounds</dc:title><upnp:class>object.container.#stationDetailGridItemView</upnp:class><desc id="cdudn" nameSpace="urn:schemas-rinconnetworks-com:metadata-1-0/">SA_RINCON83207_X_#Svc83207-0-Token</desc></item></DIDL-Lite>","sid":"","serviceName":"","upnpClass":"object.container.#stationDetailGridItemView","processingType":"queue"},{"id":"FV:2/74","title":"bryska","artist":"","album":"","description":"Artist","uri":"","artUri":"https://i.scdn.co/image/ab6761610000e5eb50680746e8d5eab6d3d98ba0","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="10052064spotify%3aartist%3a5I8Y0U8doFLVCsSY88v4Vh" parentID="10052064spotify%3aartist%3a5I8Y0U8doFLVCsSY88v4Vh" restricted="true"><dc:title>bryska</dc:title><upnp:class>object.container.person.musicArtist.#albumsList</upnp:class><desc id="cdudn" nameSpace="urn:schemas-rinconnetworks-com:metadata-1-0/">SA_RINCON2311_X_#Svc2311-0-Token</desc></item></DIDL-Lite>","sid":"","serviceName":"","upnpClass":"object.container.person.musicArtist.#albumsList","processingType":"queue"},{"id":"FV:2/65","title":"Feel Good Tunes","artist":"","album":"","description":"From BBC Sounds","uri":"","artUri":"https://ichef.bbci.co.uk/images/ic/640x640/p08r5cjj.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="10fe0064music%7emodule%7e%7econtainer_list_feel_good_tunes%7e%7eurn%3abbc%3aradio%3atag%3afeel_good_tunes" parentID="10fe0064music%7emodule%7e%7econtainer_list_feel_good_tunes%7e%7eurn%3abbc%3aradio%3atag%3afeel_good_tunes" restricted="true"><dc:title>Feel Good Tunes</dc:title><upnp:class>object.container.#stationDetailGridItemView</upnp:class><desc id="cdudn" nameSpace="urn:schemas-rinconnetworks-com:metadata-1-0/">SA_RINCON83207_X_#Svc83207-0-Token</desc></item></DIDL-Lite>","sid":"","serviceName":"","upnpClass":"object.container.#stationDetailGridItemView","processingType":"queue"},{"id":"FV:2/55","title":"Folders","artist":"","album":"","description":"From Music Library","uri":"","artUri":"","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="S:" parentID="S:" restricted="true"><dc:title>Folders</dc:title><upnp:class>object.container</upnp:class><desc id="cdudn" nameSpace="urn:schemas-rinconnetworks-com:metadata-1-0/">RINCON_AssociatedZPUDN</desc></item></DIDL-Lite>","sid":"","serviceName":"","upnpClass":"object.container","processingType":"queue"},{"id":"FV:2/75","title":"GOOD COMPANY w/ TWINSICK (Vol. 1)","artist":"","album":"","description":"By TWINSICK","uri":"x-sonos-http:track%3a1362421153.mp3?sid=160&flags=8232&sn=20","artUri":"https://i1.sndcdn.com/artworks-kUwCR2zNeeEugE66-AWS3SQ-original.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="10032028track%3a1362421153" parentID="00032028track%3a1362421153" restricted="true"><dc:title>GOOD COMPANY w/ TWINSICK (Vol. 1)</dc:title><upnp:class>object.item.audioItem.musicTrack.#editorialViewTracks</upnp:class><desc id="cdudn" nameSpace="urn:schemas-rinconnetworks-com:metadata-1-0/">SA_RINCON40967_X_#Svc40967-0-Token</desc></item></DIDL-Lite>","sid":"160","serviceName":"SoundCloud","upnpClass":"object.item.audioItem.musicTrack.#editorialViewTracks","processingType":"queue"},{"id":"FV:2/76","title":"Holy Grail Radio","artist":"","album":"","description":"Spotify Playlist","uri":"x-rincon-cpcontainer:0006002cspotify%3aplaylist%3a37i9dQZF1E8BTFWUSxNXej?sid=9&flags=44&sn=14","artUri":"https://seeded-session-images.scdn.co/v1/img/track/1q9bLSeIlGf2xBvbOkp2Wr/en","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="0006002cspotify%3aplaylist%3a37i9dQZF1E8BTFWUSxNXej" parentID="spotify%3aview%3ashortcuts" restricted="true"><dc:title>Holy Grail Radio</dc:title><upnp:class>object.container.playlistContainer#playlistItem</upnp:class><desc id="cdudn" nameSpace="urn:schemas-rinconnetworks-com:metadata-1-0/">SA_RINCON2311_X_#Svc2311-7fc72ff3-Token</desc></item></DIDL-Lite>","sid":"9","serviceName":"Spotify","upnpClass":"object.container.playlistContainer#playlistItem","processingType":"queue"},{"id":"FV:2/77","title":"KARTASHOW — Золото - Rakurs & Ramirez Remix","artist":"","album":"","description":"Spotify Playlist","uri":"x-rincon-cpcontainer:1006206cspotify%3aplaylist%3a3Y9JV1wSLbWgWGo8znQvHI?sid=9&flags=8300&sn=14","artUri":"https://mosaic.scdn.co/640/ab67616d0000b273138986018fe6fe48d1c3a8dfab67616d0000b2734ba397646cd7dba31122e092ab67616d0000b27369beab24d478b71db9ca0f6aab67616d0000b273bc2a4e41b164ae282a766cc0","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="1006206cspotify%3aplaylist%3a3Y9JV1wSLbWgWGo8znQvHI" parentID="00020000playlist:rakurs" restricted="true"><dc:title>KARTASHOW — Золото - Rakurs & Ramirez Remix</dc:title><upnp:class>object.container.playlistContainer</upnp:class><desc id="cdudn" nameSpace="urn:schemas-rinconnetworks-com:metadata-1-0/">SA_RINCON2311_X_#Svc2311-7fc72ff3-Token</desc></item></DIDL-Lite>","sid":"9","serviceName":"Spotify","upnpClass":"object.container.playlistContainer","processingType":"queue"},{"id":"FV:2/67","title":"Listen Live","artist":"","album":"","description":"From BBC Sounds","uri":"","artUri":"","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="10fe2064experience%7emodule%7e%7elisten_live%7e%7e" parentID="00080000experience%7emodule%7e%7elisten_live%7e%7e" restricted="true"><dc:title>Listen Live</dc:title><upnp:class>object.container</upnp:class><desc id="cdudn" nameSpace="urn:schemas-rinconnetworks-com:metadata-1-0/">SA_RINCON83207_X_#Svc83207-0-Token</desc></item></DIDL-Lite>","sid":"","serviceName":"","upnpClass":"object.container","processingType":"queue"},{"id":"FV:2/57","title":"Made For Przemysław","artist":"","album":"","description":"From Spotify","uri":"","artUri":"","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="10fe2064spotify%3aview%3amade-for-x" parentID="00080024spotify%3aview%3amade-for-x" restricted="true"><dc:title>Made for Przemyslaw</dc:title><upnp:class>object.container</upnp:class><desc id="cdudn" nameSpace="urn:schemas-rinconnetworks-com:metadata-1-0/">SA_RINCON2311_X_#Svc2311-0-Token</desc></item></DIDL-Lite>","sid":"","serviceName":"","upnpClass":"object.container","processingType":"queue"},{"id":"FV:2/56","title":"Malomiasteczkowy","artist":"","album":"","description":"Album by Dawid Podsiadło","uri":"x-rincon-playlist:RINCON_949F3E6DDAE401400#A:ALBUMARTIST/Dawid%20Podsiad%c5%82o/Malomiasteczkowy","artUri":"http://192.168.1.84:1400/getaa?u=x-file-cifs%3a%2f%2fMBL3TB%2fBednarz%2ftorrents%2fMovies%2fDownload%2fMalomiasteczkowy%2520flac%2f01%2520-%2520Cantate%2520Tutti.flac&v=60","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="A:ALBUMARTIST/Dawid%20Podsiad%c5%82o/Malomiasteczkowy" parentID="A:ALBUMARTIST/Dawid%20Podsiad%c5%82o" restricted="true"><dc:title>Malomiasteczkowy</dc:title><upnp:class>object.container.album.musicAlbum</upnp:class><desc id="cdudn" nameSpace="urn:schemas-rinconnetworks-com:metadata-1-0/">RINCON_AssociatedZPUDN</desc></item></DIDL-Lite>","sid":"","serviceName":"","upnpClass":"object.container.album.musicAlbum","processingType":"queue"},{"id":"FV:2/52","title":"PR1 Jedynka","artist":"","album":"","description":"TuneIn Station","uri":"x-sonosapi-stream:s15980?sid=254&flags=8224&sn=0","artUri":"http://cdn-radiotime-logos.tunein.com/s15980q.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="F10092020s15980" parentID="F00020000search%3astation:Jedynka" restricted="true"><dc:title>PR1 Jedynka</dc:title><upnp:class>object.item.audioItem.audioBroadcast</upnp:class><desc id="cdudn" nameSpace="urn:schemas-rinconnetworks-com:metadata-1-0/">SA_RINCON65031_</desc></item></DIDL-Lite>","sid":"254","serviceName":"TuneIn","upnpClass":"object.item.audioItem.audioBroadcast","processingType":"stream"},{"id":"FV:2/61","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=17","artUri":"https://sounds.files.bbci.co.uk/2.3.0/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="00020000stations:BBC radio 1" restricted="true"><dc:title>Radio 1</dc:title><upnp:class>object.item.audioItem.audioBroadcast.#none</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.#none","processingType":"stream"},{"id":"FV:2/62","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=17","artUri":"https://sounds.files.bbci.co.uk/2.3.0/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="00020000stations:BBC radio 1" restricted="true"><dc:title>Radio 1 Dance</dc:title><upnp:class>object.item.audioItem.audioBroadcast.#none</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.#none","processingType":"stream"},{"id":"FV:2/63","title":"Radio 1 relax","artist":"","album":"","description":"BBC Sounds Station","uri":"x-sonosapi-hls:stations%7eplayable%7e%7ebbc_radio_one_relax%7e%7eurn%3abbc%3aradio%3anetwork%3abbc_radio_one_relax?sid=325&flags=288&sn=17","artUri":"https://sounds.files.bbci.co.uk/2.3.0/networks/bbc_radio_one_relax/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_relax%7e%7eurn%3abbc%3aradio%3anetwork%3abbc_radio_one_relax" parentID="00020000stations:BBC radio 1" restricted="true"><dc:title>Radio 1 relax</dc:title><upnp:class>object.item.audioItem.audioBroadcast.#none</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.#none","processingType":"stream"},{"id":"FV:2/64","title":"Radio 1Xtra","artist":"","album":"","description":"BBC Sounds Station","uri":"x-sonosapi-hls:stations%7eplayable%7e%7ebbc_1xtra%7e%7eurn%3abbc%3aradio%3anetwork%3abbc_1xtra?sid=325&flags=288&sn=17","artUri":"https://sounds.files.bbci.co.uk/2.3.0/networks/bbc_1xtra/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_1xtra%7e%7eurn%3abbc%3aradio%3anetwork%3abbc_1xtra" parentID="00020000stations:BBC radio 1" restricted="true"><dc:title>Radio 1Xtra</dc:title><upnp:class>object.item.audioItem.audioBroadcast.#none</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.#none","processingType":"stream"},{"id":"FV:2/53","title":"Radio Opole","artist":"","album":"","description":"TuneIn Station","uri":"x-sonosapi-stream:s25164?sid=254&flags=8224&sn=0","artUri":"http://cdn-radiotime-logos.tunein.com/s25164q.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="F10092020s25164" parentID="F00020000search%3astation:Opole" restricted="true"><dc:title>Radio Opole</dc:title><upnp:class>object.item.audioItem.audioBroadcast</upnp:class><desc id="cdudn" nameSpace="urn:schemas-rinconnetworks-com:metadata-1-0/">SA_RINCON65031_</desc></item></DIDL-Lite>","sid":"254","serviceName":"TuneIn","upnpClass":"object.item.audioItem.audioBroadcast","processingType":"stream"},{"id":"FV:2/15","title":"Radio Plus 100.7 (Adult Contemporary Music)","artist":"","album":"","description":"TuneIn Station","uri":"x-sonosapi-stream:s9337?sid=254&flags=8224&sn=0","artUri":"http://cdn-radiotime-logos.tunein.com/s9337q.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="F10092020s9337" parentID="F10082064r102192" restricted="true"><dc:title>Radio Plus 100.7 (Adult Contemporary Music)</dc:title><upnp:class>object.item.audioItem.audioBroadcast</upnp:class><desc id="cdudn" nameSpace="urn:schemas-rinconnetworks-com:metadata-1-0/">SA_RINCON65031_</desc></item></DIDL-Lite>","sid":"254","serviceName":"TuneIn","upnpClass":"object.item.audioItem.audioBroadcast","processingType":"stream"},{"id":"FV:2/5","title":"Radio RMF FM","artist":"","album":"","description":"TuneIn Station","uri":"x-sonosapi-stream:s1217?sid=254&flags=8224&sn=0","artUri":"http://cdn-profiles.tunein.com/s1217/images/logoq.png?t=636353","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="F10092020s1217" parentID="F00020000search%3astation:RMF FM" restricted="true"><dc:title>Radio RMF FM</dc:title><upnp:class>object.item.audioItem.audioBroadcast</upnp:class><desc id="cdudn" nameSpace="urn:schemas-rinconnetworks-com:metadata-1-0/">SA_RINCON65031_</desc></item></DIDL-Lite>","sid":"254","serviceName":"TuneIn","upnpClass":"object.item.audioItem.audioBroadcast","processingType":"stream"},{"id":"FV:2/18","title":"Radio RMF FM 96.1 (Adult Contemporary Music)","artist":"","album":"","description":"TuneIn Station","uri":"x-sonosapi-stream:s76128?sid=254&flags=8224&sn=0","artUri":"http://cdn-profiles.tunein.com/s1217/images/logoq.png?t=636353","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="F10092020s76128" parentID="F10082064r102192" restricted="true"><dc:title>Radio RMF FM 96.1 (Adult Contemporary Music)</dc:title><upnp:class>object.item.audioItem.audioBroadcast</upnp:class><desc id="cdudn" nameSpace="urn:schemas-rinconnetworks-com:metadata-1-0/">SA_RINCON65031_</desc></item></DIDL-Lite>","sid":"254","serviceName":"TuneIn","upnpClass":"object.item.audioItem.audioBroadcast","processingType":"stream"},{"id":"FV:2/60","title":"Radio RMF MAXXX","artist":"","album":"","description":"TuneIn Station","uri":"x-sonosapi-stream:s48192?sid=254&flags=8224&sn=0","artUri":"http://cdn-profiles.tunein.com/s48192/images/logoq.png?t=636353","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="F10092020s48192" parentID="F00090008s48192" restricted="true"><dc:title>

Computers are very dumb and only do exactly what you tell them. There is a big difference between a text string being comma separated values, or a list of strings separated by commas, or even an array of strings.

“this, and that, and the other”
“this”, “and that”, “and the other”
[“this”, “and that”, “and the other”]

The first is a string, the second is a CSV list of strings, the third is an array of strings (please note [] for array) and whilst we might glance over the subtle difference, the computer does not.

Your original question was ‘how do I get an array of 30 objects into one list?’ I believe what you really wanted to know was ‘how do I get data in this format (array of 30 objects) into this format for a service call (where I actually want a list of ‘title’ from the first object)?’

Note too that there is a big difference between " and '. Both can be used (in most computer languages) to enclose and denote a string variable. Used together they allow for embedding a quote " within a string, otherwise how could we get a string like “this is my quote mark " within my string”?

For us humans, we can see from context that the middle " is just a character in the text. The computer however has a fit of temperament as " must match start-end of a string literal. Therefore, using different types of quotes " or ’ allows us to embed a quote of the other type in a string. Your change has made the string

’ my first song ", " my second song ", " my third song’

which is just one long string with quote marks in it. The computer has a good go at this, but when faced with something that it really can’t display, it often resorts to showing &quot as a way of saying this should be a " but I can’t print this.

Now I know a bit more about what I think you are tyring to do, I guess you want a service call to set the option list for an input dropdown. The answer is to use the following directly in the service call:

{"options": payload.title}

If you have a msg.payload with the array of objects containing the titles,
and you pass this directly into a service call node,
and you set the service call as below
then the JSONata expression above will produce the object required for the ‘data’ option.

{ “options” : [“title 1”, “title 2”, “title 3”]}

This is an object, where the ‘options’ field is an array of strings, and the strings are your titles from your msg.payload!

I have tested this using your debug data (yes it is too big for the post, but easy enough to trim and fix) going directly into a service call. It works for me!

and after the service call…

Hopefully this is what you really wanted to know!

@Biscuit - thank you so much for explaining the differences. I should have really explain it all in the OP what I wanted to achieve.
Therefore - I have copied your original code:

$reduce(payload.title, function($acc, $val){$acc & ", " & $val})

and used it in change node, and also set the call service node with:

{"options": payload.title}

and I am getting this error:

image

This is my flow:

[{"id":"30bdaec5520253bf","type":"function","z":"beebe84ddfd64199","name":"function 2","func":"msg.payload = msg.payload.filter(el => msg.include.includes(el.description));\nnode.warn(msg.payload);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":660,"y":3240,"wires":[["4004b58fb45bf1d7"]]},{"id":"1f6174063d0d80c2","type":"sonos-manage-mysonos","z":"beebe84ddfd64199","confignode":"71bb997c7dccf5d5","command":"mysonos.get.items","state":"","stateType":"str","avoidCheckPlayerAvailability":false,"name":"","x":470,"y":3240,"wires":[["30bdaec5520253bf"]]},{"id":"4004b58fb45bf1d7","type":"change","z":"beebe84ddfd64199","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$reduce(payload.title, function($acc, $val){$acc & \", \" & $val})","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":840,"y":3240,"wires":[["af5b610215b2956c"]]},{"id":"a9e9917af43aa7b6","type":"inject","z":"beebe84ddfd64199","name":"trigger","props":[{"p":"payload"},{"p":"include","v":"[\"Spotify Playlist\"]","vt":"json"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":410,"y":3320,"wires":[["1f6174063d0d80c2"]]},{"id":"af5b610215b2956c","type":"api-call-service","z":"beebe84ddfd64199","name":"","server":"5ab38d6d.319fe4","version":5,"debugenabled":false,"domain":"input_select","service":"set_options","areaId":[],"deviceId":[],"entityId":["input_select.sonos_select_media"],"data":"{\"options\": payload.title}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1090,"y":3240,"wires":[[]]},{"id":"71bb997c7dccf5d5","type":"sonos-config","name":"kitchen","serialnum":"48-A6-B8-F9-67-C4:1","ipaddress":"192.168.1.84"},{"id":"5ab38d6d.319fe4","type":"server","name":"Home Assistant 17","version":5,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":30,"areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m","enableGlobalContextStore":true}]

I must be making some sort of silly error (I hope?) somewhere, for this code to not working - when it works for you.

Thank you

EDIT

I have now found out where the mistake was - it was within the change node - should have used msg.payload.title instead of just msg.payload.

This now works as intended - passes the info into desired input_select.

Thank you once again for your help!


Hello Guys,
I quite new in Node Red, I facing something similar. I’m have this array for multiple sensors. I need to split each mqtt message into ID of the sensor in order I can check each temperature data.

Thank you all.

Hi Fabricio

This should be something that can be done, however it always helps to know first what you are trying to do with the data. (I spent a lot of time answering a previous post by trying to guess what was wanted!)

It also helps to have a copy of the real data to work with - it can take ages to type stuff in by hand for testing.

  • can you copy your data object (first check that there is nothing personal or secret in the data) and post here please?
    If you mouse-over the debug window as shown in your picture, on the right of the Varray[13] you should see a ‘copy’ icon appear. Click on this to copy the entire msg.payload object, and past it here using the “</>” symbol at the top of the edit window (this inserts a set of backticks and you can paste in the data in between the ticks

You should get to see something like:

{"_msgid":"687ef37596351270","payload":"Tuesday March 26, 15:24 PM +0000","topic":""}

and this is very easy to copy-paste and use to test and understand the data structure!

  • can you also please explain a little more what your data is, and what you want to end up with?
    Is the array 13 different sensors, and the ID of the sensor is the ‘bn’ field (“4B4E…”)?

Do you just want to end up with an array of the ‘bn’ fields? If you already have a flow, perhaps using a service call to do something with these sensor IDs, then posting that flow would also help too!