Plex BodyPayload convert JSON

Hello, I’m new to the community, moreover, I’m French so excuse me in advance about the level of my English.

I created a script with a Plex webhook that allows me to retrieve the information, however the “body” of my JSon feed includes a payload part that I can’t decode in JSon format.
Here is an example of the feed I get

[
{
"headers": {
"host": "5xxxxxxxxxxxxxxx.net:5678",
"user-agent": "PlexMediaServer/1.25.6.5577-c8bd13540",
"accept": "*/*",
"accept-encoding": "gzip",
"content-length": "19842",
"content-type": "multipart/form-data; boundary=------------------------c6f31d998fc89029"
},
"params": {
},
"query": {
},
"body": {
"payload": "{"event":"media.play","user":true,"owner":true,"Account":{"id":1,"thumb":"https://plex.tv/users/03fb11a5da0144fb/avatar?c=1642101976","title":"NSellier"},"Server":{"title":"ALICE","uuid":"3c1524128a3a5c86266a6f95ca6b807b34de4091"},"Player":{"local":true,"publicAddress":"86.239.72.194","title":"Chrome","uuid":"tf0z1rd8hs9nmsqzgdhj9182"},"Metadata":{"librarySectionType":"movie","ratingKey":"1762","key":"/library/metadata/1762","guid":"plex://movie/5d776c20594b2b001e6ebc45","studio":"Original Film","type":"movie","title":"Fast & Furious 9","librarySectionTitle":"Films-4K","librarySectionID":1,"librarySectionKey":"/library/sections/1","originalTitle":"F9: The Fast Saga","contentRating":"fr/Tous publics","summary":"Dominic Toretto mène une vie tranquille avec Letty et son fils, le petit Brian, mais ils savent que le danger se cache toujours derrière l'horizon paisible. Cette fois, cette menace obligera Dom à affronter les péchés de son passé s’il veut sauver ceux qu’il aime le plus. Son équipe se réunit pour arrêter un complot bouleversant mené par l'assassin le plus talentueux et le meilleur pilote qu'ils aient jamais rencontré: un homme qui se trouve être également le frère abandonné de Dom, Jakob.","rating":5.9,"audienceRating":8.2,"viewOffset":70000,"skipCount":4,"lastViewedAt":1646840148,"year":2021,"tagline":"Les liens de sang ne font pas la famille.","thumb":"/library/metadata/1762/thumb/1645781222","art":"/library/metadata/1762/art/1645781222","duration":8580000,"originallyAvailableAt":"2021-06-25","addedAt":1642099748,"updatedAt":1645781222,"audienceRatingImage":"rottentomatoes://image.rating.upright","chapterSource":"media","primaryExtraKey":"/library/metadata/1764","ratingImage":"rottentomatoes://image.rating.rotten","Genre":[{"id":7,"filter":"genre=7","tag":"Thriller","count":99},{"id":13939,"filter":"genre=13939","tag":"Action","count":159},{"id":13728,"filter":"genre=13728","tag":"Adventure","count":148},{"id":1929,"filter":"genre=1929","tag":"Crime","count":47}],"Director":[{"id":17858,"filter":"director=17858","tag":"Justin Lin","count":5}],"Writer":[{"id":17813,"filter":"writer=17813","tag":"Gary Scott Thompson","count":3},{"id":18321,"filter":"writer=18321","tag":"Justin Lin"},{"id":18322,"filter":"writer=18322","tag":"Daniel Casey"},{"id":18323,"filter":"writer=18323","tag":"Alfredo Botello"}],"Producer":[{"id":18023,"filter":"producer=18023","tag":"Clayton Townsend","count":2},{"id":17847,"filter":"producer=17847","tag":"Neal H. Moritz","count":10},{"id":17961,"filter":"producer=17961","tag":"Vin Diesel","count":7},{"id":18355,"filter":"producer=18355","tag":"Joe Roth","count":4},{"id":18356,"filter":"producer=18356","tag":"Jeff Kirschenbaum","count":3},{"id":18357,"filter":"producer=18357","tag":"Justin Lin"},{"id":18358,"filter":"producer=18358","tag":"Samantha Vincent"}],"Country":[{"id":11,"filter":"country=11","tag":"United States of America","count":239}],"Guid":[{"id":"imdb://tt5433138"},{"id":"tmdb://385128"},{"id":"tvdb://8856"}],"Rating":[{"image":"imdb://image.rating","value":5.2,"type":"audience","count":263},{"image":"rottentomatoes://image.rating.upright","value":8.2,"type":"audience","count":206},{"image":"rottentomatoes://image.rating.rotten","value":5.9,"type":"critic","count":82},{"image":"themoviedb://image.rating","value":7.3,"type":"audience","count":263}],"Collection":[{"id":17904,"filter":"collection=17904","tag":"Fast & Furious - Saga","count":9,"guid":"plex://collection/5ec2ec219b196d0042897ef7","summary":"Fast and Furious est une série de films d'action avec comme toile de fond les courses de rue illégales et des braquages."}],"Role":[{"id":17819,"filter":"actor=17819","tag":"Vin Diesel","count":12,"role":"Dominic Toretto","thumb":"https://metadata-static.plex.tv/2/people/26d8aa12b1e49fc62d805dfcf0f6837d.jpg"},{"id":17820,"filter":"actor=17820","tag":"Michelle Rodriguez","count":11,"role":"Letty Ortiz","thumb":"https://metadata-static.plex.tv/b/people/be8b00770f4d0173425d7e07316e3ece.jpg"},{"id":17966,"filter":"actor=17966","tag":"Tyrese Gibson","count":6,"role":"Roman Pearce","thumb":"https://metadata-static.plex.tv/f/people/fae1d848092b678572d0c1ccf2bafc1f.jpg"},{"id":17967,"filter":"actor=17967","tag":"Ludacris","count":6,"role":"Tej Parker","thumb":"https://metadata-static.plex.tv/3/people/3cef46981718b30ce26b93b5598d2a00.jpg"},{"id":18324,"filter":"actor=18324","tag":"John Cena","count":3,"role":"Jakob Toretto","thumb":"https://metadata-static.plex.tv/0/people/0fe1863a3e1b964760bb5357915f7d66.jpg"},{"id":18033,"filter":"actor=18033","tag":"Nathalie Emmanuel","count":3,"role":"Ramsey","thumb":"https://metadata-static.plex.tv/a/people/a4a0e3ef37c3d3353800ebe1b8de2d64.jpg"},{"id":17821,"filter":"actor=17821","tag":"Jordana Brewster","count":6,"role":"Mia Toretto","thumb":"https://metadata-static.plex.tv/8/people/89b7c6491ab7668bead7b325b1bf3e4e.jpg"},{"id":16909,"filter":"actor=16909","tag":"Sung Kang","count":7,"role":"Han Lue","thumb":"https://metadata-static.plex.tv/1/people/14e248ba1b0d8db0e0a6afbdd77431c5.jpg"},{"id":18325,"filter":"actor=18325","tag":"Michael Rooker","count":4,"role":"Buddy","thumb":"https://metadata-static.plex.tv/0/people/0a05834e374c60d2deda8b1c1bbe3c69.jpg"},{"id":18128,"filter":"actor=18128","tag":"Helen Mirren","count":5,"role":"Magdalene 'Queenie' Shaw","thumb":"https://metadata-static.plex.tv/a/people/a565a7ab72b02d8e98c36fe9203c9413.jpg"},{"id":18034,"filter":"actor=18034","tag":"Kurt Russell","count":5,"role":"Mr. Nobody","thumb":"https://metadata-static.plex.tv/a/people/ada71a2b9ba38388e8fe95037f09a7ed.jpg"},{"id":18078,"filter":"actor=18078","tag":"Charlize Theron","count":4,"role":"Cipher","thumb":"https://metadata-static.plex.tv/7/people/734b7e97cc402ae2f9b493566c0d8004.jpg"},{"id":18326,"filter":"actor=18326","tag":"Cardi B","role":"Leysa","thumb":"https://metadata-static.plex.tv/2/people/2ddb409dcd5c1e037ebd768adee5d018.jpg"},{"id":18327,"filter":"actor=18327","tag":"Anna Sawai","role":"Elle","thumb":"https://metadata-static.plex.tv/d/people/def34c874ad1a2b16aa5c839d434ef76.jpg"},{"id":17860,"filter":"actor=17860","tag":"Lucas Black","count":3,"role":"Sean Boswell","thumb":"https://metadata-static.plex.tv/9/people/933794b0b2ec9417b1a7576283239ccf.jpg"},{"id":17862,"filter":"actor=17862","tag":"Shad Moss","count":3,"role":"Twinkie","thumb":"https://metadata-static.plex.tv/5/people/502338bb8fc43fd772e60ede03e78797.jpg"},{"id":17867,"filter":"actor=17867","tag":"Jason Tobin","count":2,"role":"Earl Hu","thumb":"https://metadata-static.plex.tv/people/5d7768332ec6b5001f6bba15.jpg"},{"id":18328,"filter":"actor=18328","tag":"Thue Ersted Rasmussen","role":"Otto"},{"id":17909,"filter":"actor=17909","tag":"Don Omar","count":5,"role":"Rico Santos","thumb":"https://metadata-static.plex.tv/people/5d77683b8718ba001e315f4d.jpg"},{"id":17911,"filter":"actor=17911","tag":"Shea Whigham","count":6,"role":"Agent Stasiak","thumb":"https://metadata-static.plex.tv/people/5d7768346f4521001ea9bd3e.jpg"},{"id":18329,"filter":"actor=18329","tag":"Vincent Sinclair Diesel","role":"Younger Dom"},{"id":18330,"filter":"actor=18330","tag":"Finn Cole","role":"Young Jakob","thumb":"https://metadata-static.plex.tv/a/people/a1b908faee3101addda5eee99bbb81f3.jpg"},{"id":18331,"filter":"actor=18331","tag":"Vinnie Bennett","count":2,"role":"Young Dom","thumb":"https://metadata-static.plex.tv/people/5d776a3d51dd69001fe2142d.jpg"},{"id":18332,"filter":"actor=18332","tag":"J. D. Pardo","count":2,"role":"Jack Toretto","thumb":"https://metadata-static.plex.tv/people/5d776838103a2d001f568555.jpg"},{"id":18333,"filter":"actor=18333","tag":"Jim Parrack","count":2,"role":"Kenny Linder","thumb":"https://metadata-static.plex.tv/people/5d77683b999c64001ec30675.jpg"},{"id":18334,"filter":"actor=18334","tag":"Lex Elle","role":"Sergeant Reyes","thumb":"https://metadata-static.plex.tv/people/5e165541316a39003efa0323.jpg"},{"id":18335,"filter":"actor=18335","tag":"Krzysztof Mardula","count":2,"role":"Thug","thumb":"https://metadata-static.plex.tv/d/people/dc33b6c03e85b3055934ffc0378b978f.jpg"},{"id":16646,"filter":"actor=16646","tag":"Amber Sienna","count":2,"role":"Interpol","thumb":"https://metadata-static.plex.tv/9/people/9bc77534d8c2df4e65d6923794742cab.jpg"},{"id":18336,"filter":"actor=18336","tag":"Martyn Ford","count":2,"role":"Lieutenant Sue","thumb":"https://metadata-static.plex.tv/people/5d776bbead5437001f7a8bcd.jpg"},{"id":18337,"filter":"actor=18337","tag":"Albert Giannitelli","role":"Technician"},{"id":18338,"filter":"actor=18338","tag":"Ozuna","role":"Young Santos","thumb":"https://metadata-static.plex.tv/0/people/0b93b7b6b5a707325a177d7cfd80bfd3.jpg"},{"id":18339,"filter":"actor=18339","tag":"Méghane De Croock","role":"Otto's Entourage","thumb":"https://metadata-static.plex.tv/8/people/84b713a8788159ac6655c0b3be53df19.jpg"},{"id":18340,"filter":"actor=18340","tag":"Bad Bunny","role":"Lookout","thumb":"https://metadata-static.plex.tv/d/people/d5b92122c141a8685ad187f374246d29.jpg"},{"id":18341,"filter":"actor=18341","tag":"Siena Agudong","role":"Young Mia","thumb":"https://metadata-static.plex.tv/people/5d776edcfb0d55001f5d0e22.jpg"},{"id":18342,"filter":"actor=18342","tag":"Isaac Holtane","role":"Little Brian"},{"id":18343,"filter":"actor=18343","tag":"Immanuel Holtane","role":"Little Brian"},{"id":18344,"filter":"actor=18344","tag":"Azia Dinea Hale","role":"Young Letty"},{"id":18345,"filter":"actor=18345","tag":"Juju Zhang","role":"Young Elle"},{"id":18346,"filter":"actor=18346","tag":"Karson Kern","role":"Young Vince","thumb":"https://metadata-static.plex.tv/people/5d776cc296b655001fe3a6be.jpg"},{"id":18347,"filter":"actor=18347","tag":"Igby Rigney","role":"Young Jesse","thumb":"https://metadata-static.plex.tv/3/people/3d6abcdfc844d894afdd4c564e03721e.jpg"},{"id":18348,"filter":"actor=18348","tag":"Sophia Tatum","role":"Racer Chick"},{"id":18349,"filter":"actor=18349","tag":"Francis Ngannou","role":"Ferocious Professional","thumb":"https://metadata-static.plex.tv/people/5d776c71ad5437001f7be38d.jpg"},{"id":18350,"filter":"actor=18350","tag":"Cered","role":"Young Leo"},{"id":18351,"filter":"actor=18351","tag":"Oqwe Lin","role":"'Hey' Kid"},{"id":18352,"filter":"actor=18352","tag":"Bill Simmons","role":"Linder Pit Crew"},{"id":18353,"filter":"actor=18353","tag":"Luka Hays","role":"Deputy"},{"id":18354,"filter":"actor=18354","tag":"Jimmy Lin","role":"Lookout"},{"id":18021,"filter":"actor=18021","tag":"Jason Statham","count":6,"role":"Deckard Shaw (uncredited)","thumb":"https://metadata-static.plex.tv/people/5d776826e6d55c002040af58.jpg"}]}}"
}
}
]

So I would like to split the “payload” in JSon format to be able to retrieve the values ​​in my script.

Thank you in advance for your help on the subject. I don’t know how to write the required function.

Information on your n8n setup

  • n8n version: 0.165.1
  • Database SQLite
  • Running n8n via Docker:

Hey @NSellier, welcome to the community :tada:

Are you able to use JSON.parse() to parse the JSON string inside your payload field? I.e. if you connect your webhook node to a Function Item node running something like return JSON.parse(item.body.payload);, would this return the structure you have in mind (you might need to adjust your expressions on the Switch node slightly)?

Example Workflow

Perfect !!! Thanks it’s work