How to use/access a message variable to navigate an array with a JSONata expression in a switch node?

Hello all,

I'm struggling trying to use/access a message variable to navigate an array with a JSONata expression in a switch node.

The message variable is "index", and is well declared.

I've tried all I could, but it is not working:

image

image

image

image

I've had a similar issue in the past, fixed here but the problem/requirement was slightly different since I was using a change node, and flowContext.

code is attached
flows.json (7.0 KB)

Thanks

You have not supplied any incoming data and no one can copy the text in those images.
image 3 looks closest
$$.payload.streams[$$.index].tags.langauge should work at a guess as i have no idea of your data. I don't think you can mix $$ and msg, one or the other, msg will put jsonata in compatibility mode.

Sorry @E1cid

here is the code :slight_smile:

flows.json (7.0 KB)

Looking at your flow is very confusing, What exactly are you trying to do?

Hi @E1cid

Im trying to move the parameter streams[index].tag.language to streams[index].language, if it exists.

I would use the transform function

[{"id":"a9348d92797fed33","type":"inject","z":"bf9e1e33.030598","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":510,"y":1940,"wires":[["e353ab05c11e2d03"]]},{"id":"e353ab05c11e2d03","type":"change","z":"bf9e1e33.030598","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\"program_id\":16,\"program_num\":16,\"pcr_pid\":620,\"streams\":[{\"codec_type\":\"video\",\"id\":\"0x26c\",\"disposition\":{\"default\":0,\"dub\":0,\"original\":0,\"comment\":0,\"lyrics\":0,\"karaoke\":0,\"forced\":0,\"hearing_impaired\":0,\"visual_impaired\":0,\"clean_effects\":0,\"attached_pic\":0,\"timed_thumbnails\":0,\"captions\":0,\"descriptions\":0,\"metadata\":0,\"dependent\":0,\"still_image\":0}},{\"codec_type\":\"audio\",\"id\":\"0x277\",\"disposition\":{\"default\":0,\"dub\":0,\"original\":0,\"comment\":0,\"lyrics\":0,\"karaoke\":0,\"forced\":0,\"hearing_impaired\":0,\"visual_impaired\":0,\"clean_effects\":0,\"attached_pic\":0,\"timed_thumbnails\":0,\"captions\":0,\"descriptions\":0,\"metadata\":0,\"dependent\":0,\"still_image\":0},\"tags\":{\"language\":\"eng\"}},{\"codec_type\":\"audio\",\"id\":\"0x278\",\"disposition\":{\"default\":0,\"dub\":0,\"original\":0,\"comment\":0,\"lyrics\":0,\"karaoke\":0,\"forced\":0,\"hearing_impaired\":0,\"visual_impaired\":0,\"clean_effects\":0,\"attached_pic\":0,\"timed_thumbnails\":0,\"captions\":0,\"descriptions\":0,\"metadata\":0,\"dependent\":0,\"still_image\":0},\"tags\":{\"language\":\"qab\"}},{\"codec_type\":\"subtitle\",\"id\":\"0x280\",\"disposition\":{\"default\":0,\"dub\":0,\"original\":0,\"comment\":0,\"lyrics\":0,\"karaoke\":0,\"forced\":0,\"hearing_impaired\":0,\"visual_impaired\":0,\"clean_effects\":0,\"attached_pic\":0,\"timed_thumbnails\":0,\"captions\":0,\"descriptions\":0,\"metadata\":0,\"dependent\":0,\"still_image\":0},\"tags\":{\"language\":\"eng\"}},{\"codec_type\":\"subtitle\",\"id\":\"0x281\",\"disposition\":{\"default\":0,\"dub\":0,\"original\":0,\"comment\":0,\"lyrics\":0,\"karaoke\":0,\"forced\":0,\"hearing_impaired\":0,\"visual_impaired\":0,\"clean_effects\":0,\"attached_pic\":0,\"timed_thumbnails\":0,\"captions\":0,\"descriptions\":0,\"metadata\":0,\"dependent\":0,\"still_image\":0},\"tags\":{\"language\":\"zho\"}},{\"codec_type\":\"subtitle\",\"id\":\"0x282\",\"disposition\":{\"default\":0,\"dub\":0,\"original\":0,\"comment\":0,\"lyrics\":0,\"karaoke\":0,\"forced\":0,\"hearing_impaired\":0,\"visual_impaired\":0,\"clean_effects\":0,\"attached_pic\":0,\"timed_thumbnails\":0,\"captions\":0,\"descriptions\":0,\"metadata\":0,\"dependent\":0,\"still_image\":0},\"tags\":{\"language\":\"msa\"}},{\"codec_type\":\"subtitle\",\"id\":\"0x283\",\"disposition\":{\"default\":0,\"dub\":0,\"original\":0,\"comment\":0,\"lyrics\":0,\"karaoke\":0,\"forced\":0,\"hearing_impaired\":0,\"visual_impaired\":0,\"clean_effects\":0,\"attached_pic\":0,\"timed_thumbnails\":0,\"captions\":0,\"descriptions\":0,\"metadata\":0,\"dependent\":0,\"still_image\":0},\"tags\":{\"language\":\"tam\"}},{\"id\":\"0x2a8\",\"disposition\":{\"default\":0,\"dub\":0,\"original\":0,\"comment\":0,\"lyrics\":0,\"karaoke\":0,\"forced\":0,\"hearing_impaired\":0,\"visual_impaired\":0,\"clean_effects\":0,\"attached_pic\":0,\"timed_thumbnails\":0,\"captions\":0,\"descriptions\":0,\"metadata\":0,\"dependent\":0,\"still_image\":0}}],\"service_name\":\"CNA\",\"service_provider\":\"mediacorp\"}","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":270,"y":1840,"wires":[["412aeca37583d06d"]]},{"id":"412aeca37583d06d","type":"change","z":"bf9e1e33.030598","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$$.payload ~> |streams| {\"langauage\": $.tags.language}, [\"tags\"]|\t\t","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":520,"y":1840,"wires":[["cf16e07496d3f02d"]]},{"id":"cf16e07496d3f02d","type":"debug","z":"bf9e1e33.030598","name":"Issue is here","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":780,"y":1840,"wires":[]}]

Transform

$$.payload ~> |streams| {"langauage": $.tags.language}, ["tags"]|		

Or low code option

[{"id":"a9348d92797fed33","type":"inject","z":"bf9e1e33.030598","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"program_id\":16,\"program_num\":16,\"pcr_pid\":620,\"streams\":[{\"codec_type\":\"video\",\"id\":\"0x26c\",\"disposition\":{\"default\":0,\"dub\":0,\"original\":0,\"comment\":0,\"lyrics\":0,\"karaoke\":0,\"forced\":0,\"hearing_impaired\":0,\"visual_impaired\":0,\"clean_effects\":0,\"attached_pic\":0,\"timed_thumbnails\":0,\"captions\":0,\"descriptions\":0,\"metadata\":0,\"dependent\":0,\"still_image\":0}},{\"codec_type\":\"audio\",\"id\":\"0x277\",\"disposition\":{\"default\":0,\"dub\":0,\"original\":0,\"comment\":0,\"lyrics\":0,\"karaoke\":0,\"forced\":0,\"hearing_impaired\":0,\"visual_impaired\":0,\"clean_effects\":0,\"attached_pic\":0,\"timed_thumbnails\":0,\"captions\":0,\"descriptions\":0,\"metadata\":0,\"dependent\":0,\"still_image\":0},\"tags\":{\"language\":\"eng\"}},{\"codec_type\":\"audio\",\"id\":\"0x278\",\"disposition\":{\"default\":0,\"dub\":0,\"original\":0,\"comment\":0,\"lyrics\":0,\"karaoke\":0,\"forced\":0,\"hearing_impaired\":0,\"visual_impaired\":0,\"clean_effects\":0,\"attached_pic\":0,\"timed_thumbnails\":0,\"captions\":0,\"descriptions\":0,\"metadata\":0,\"dependent\":0,\"still_image\":0},\"tags\":{\"language\":\"qab\"}},{\"codec_type\":\"subtitle\",\"id\":\"0x280\",\"disposition\":{\"default\":0,\"dub\":0,\"original\":0,\"comment\":0,\"lyrics\":0,\"karaoke\":0,\"forced\":0,\"hearing_impaired\":0,\"visual_impaired\":0,\"clean_effects\":0,\"attached_pic\":0,\"timed_thumbnails\":0,\"captions\":0,\"descriptions\":0,\"metadata\":0,\"dependent\":0,\"still_image\":0},\"tags\":{\"language\":\"eng\"}},{\"codec_type\":\"subtitle\",\"id\":\"0x281\",\"disposition\":{\"default\":0,\"dub\":0,\"original\":0,\"comment\":0,\"lyrics\":0,\"karaoke\":0,\"forced\":0,\"hearing_impaired\":0,\"visual_impaired\":0,\"clean_effects\":0,\"attached_pic\":0,\"timed_thumbnails\":0,\"captions\":0,\"descriptions\":0,\"metadata\":0,\"dependent\":0,\"still_image\":0},\"tags\":{\"language\":\"zho\"}},{\"codec_type\":\"subtitle\",\"id\":\"0x282\",\"disposition\":{\"default\":0,\"dub\":0,\"original\":0,\"comment\":0,\"lyrics\":0,\"karaoke\":0,\"forced\":0,\"hearing_impaired\":0,\"visual_impaired\":0,\"clean_effects\":0,\"attached_pic\":0,\"timed_thumbnails\":0,\"captions\":0,\"descriptions\":0,\"metadata\":0,\"dependent\":0,\"still_image\":0},\"tags\":{\"language\":\"msa\"}},{\"codec_type\":\"subtitle\",\"id\":\"0x283\",\"disposition\":{\"default\":0,\"dub\":0,\"original\":0,\"comment\":0,\"lyrics\":0,\"karaoke\":0,\"forced\":0,\"hearing_impaired\":0,\"visual_impaired\":0,\"clean_effects\":0,\"attached_pic\":0,\"timed_thumbnails\":0,\"captions\":0,\"descriptions\":0,\"metadata\":0,\"dependent\":0,\"still_image\":0},\"tags\":{\"language\":\"tam\"}},{\"id\":\"0x2a8\",\"disposition\":{\"default\":0,\"dub\":0,\"original\":0,\"comment\":0,\"lyrics\":0,\"karaoke\":0,\"forced\":0,\"hearing_impaired\":0,\"visual_impaired\":0,\"clean_effects\":0,\"attached_pic\":0,\"timed_thumbnails\":0,\"captions\":0,\"descriptions\":0,\"metadata\":0,\"dependent\":0,\"still_image\":0}}],\"service_name\":\"CNA\",\"service_provider\":\"mediacorp\"}","payloadType":"json","x":190,"y":1920,"wires":[["e353ab05c11e2d03"]]},{"id":"e353ab05c11e2d03","type":"change","z":"bf9e1e33.030598","name":"","rules":[{"t":"set","p":"hold","pt":"msg","to":"payload","tot":"msg"},{"t":"set","p":"payload","pt":"msg","to":"hold.streams","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":260,"y":1840,"wires":[["754baad4.93518c"]]},{"id":"754baad4.93518c","type":"split","z":"bf9e1e33.030598","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":380,"y":1880,"wires":[["412aeca37583d06d"]]},{"id":"412aeca37583d06d","type":"change","z":"bf9e1e33.030598","name":"","rules":[{"t":"set","p":"payload.language","pt":"msg","to":"payload.tags.language","tot":"msg"},{"t":"delete","p":"payload.tags","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":530,"y":1940,"wires":[["bc021cb3.4cb958"]]},{"id":"bc021cb3.4cb958","type":"join","z":"bf9e1e33.030598","name":"","mode":"auto","build":"string","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":"false","timeout":"","count":"","reduceRight":false,"x":660,"y":1900,"wires":[["deeae6d0.1c813"]]},{"id":"deeae6d0.1c813","type":"change","z":"bf9e1e33.030598","name":"","rules":[{"t":"set","p":"hold.streams","pt":"msg","to":"payload","tot":"msg"},{"t":"move","p":"hold","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":820,"y":1880,"wires":[["cf16e07496d3f02d"]]},{"id":"cf16e07496d3f02d","type":"debug","z":"bf9e1e33.030598","name":"Issue is here","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":960,"y":1820,"wires":[]}]

Thank you so much, @E1cid !

I wasn't aware about the transform function, I will have a look at it. Thanks a lot !

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.