Parsing value from nested json and create a new nested JSON

Hello guys,

First of all, thanks for this awesome tool.
Sorry if my questions seems dumb, but I’m kinda new to this.

I have a nested json data that I receive from a webhook in the following format :

{
 headers{
        "value1":"somevalue",
        "value2":"othervalue",
   }
   body{
        "id":"xxxxyy",
        "severity":"3"
        "tags":["tag1","tag2","tag3'],
   }
}

I just need to keep the body data on my side.

From this JSON, I need to create a new nested JSON in order to send a webhook to Microsoft Teams using the following structure :

{
"@type": "MessageCard",
"@context": "http://schema.org/extensions",
"themeColor": "0076D7",
"summary": "Summary Goes Here",
   "sections": [
     {
       "activityTitle": "Title",
       "activityImage": "some link to an image",
       "activityImageType": "article",
       "activitySubtitle": "Subtitle",
       "facts": [
         {
           "name": "Severity",
           "value": "High"
         },
         {
           "name": "Tags",
           "value": "tag1 tag2 tag3"
         }
       ],
       "markdown": true
     }
   ],
   "potentialAction": [
     {
       "@context": "http://schema.org",
       "@type": "ViewAction",
       "name": "action name",
       "target": [
         "some http link"
       ]
     }
   ]
 } 

I don’t really know where to begin, is it better to use a function to extract the data and then create the new json or is it better to use a “set” node to extract the data and populate the new json ?

Welcome to the community @jackbot!

It seems like you have some more complex mapping requirements as the data has to get partly transformed (in the source it seems to be a string-number and in the target a string-text). So best to do it via a Function-Node.
No idea how the mapping should work exactly but here an example:

2 Likes

Thank you Jan for the quick reply, I’ll take a look at it :slight_smile:
I’ll update the post asap.