web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id : ARxdJPpWv/OlaXQ8V2pBj9
Power Automate - Building Flows
Answered

How to parse and use the JSON data that is sent by webhook to a teams channel?

Like (1) ShareShare
ReportReport
Posted on 3 Apr 2025 10:23:57 by 12

 

 

Dear all

I am at a loss and need help.

I try to send a webhook (with JSON data) from an external source to a teams channel. It works as I do get a message in the teams channel from the external source, however, I can't parse and use the JSON data trasmitted (to post it in the teams channel message).

The interesting data I want to use in the teams message is in the body/text object in the webhook - and optimally I would like to use the different objects within said data to design a message into the teams channel.
But I can't even put the whole JSON line in the message to begin with (let alone parse it for the individual pieces of information, which is the goal I am striving for).

Can you help me figure out what I am missing?

My Flow:

See attached file

My JSON configuration/data (somewhat obfuscated):

The original JSON info from the webhook (the "body" being the interesting part for me):

{
    "headers": {
        "Accept": "*/*",
        "Host": "obfuscated",
        "Max-Forwards": "10",
        "X-ARR-LOG-ID": "obfuscated",
        "CLIENT-IP": "obfuscated",
        "DISGUISED-HOST": "obfuscated",
        "X-SITE-DEPLOYMENT-ID": "obfuscated",
        "WAS-DEFAULT-HOSTNAME": "obfuscated",
        "X-Forwarded-Proto": "https",
        "X-AppService-Proto": "https",
        "X-ARR-SSL": "obfuscated",
        "X-Forwarded-TlsVersion": "1.3",
        "X-Forwarded-For": "obfuscated",
        "X-Original-URL": "obfuscated",
        "X-WAWS-Unencoded-URL": "obfuscated",
        "Content-Length": "194",
        "Content-Type": "application/json"
    },
    "body": {
        "text": "<pre>{\n \"content\": \"obfuscated\".\n \"message\": \"\",\n \"time\": \"%%log_time%%\",\n \"username\": \"%%log_user%%\",\n \"source IP\": \"%%log_srcip%%\"\n}</pre>"
    }
}
 
The JSON information in the "parse JSON" action:
 
raw inputs:
{
    "content": {
        "text": "<pre>{\n \"content\": \"obfuscated\".\n \"message\": \"\",\n \"time\": \"%%log_time%%\",\n \"username\": \"%%log_user%%\",\n \"source IP\": \"%%log_srcip%%\"\n}</pre>"
    },
    "schema": {
        "type": "object",
        "properties": {
            "content": {
                "type": "string"
            },
            "message": {
                "type": "string"
            },
            "time": {
                "type": "string"
            },
            "username": {
                "type": "string"
            },
            "source IP": {
                "type": "string"
            }
        }
    }
}


raw ouputs:
{
    "body": {
        "text": "<pre>{\n \"content\": \"obfuscated\".\n \"message\": \"\",\n \"time\": \"%%log_time%%\",\n \"username\": \"%%log_user%%\",\n \"source IP\": \"%%log_srcip%%\"\n}</pre>"
    }
}
 
 
I have the same question (0)
  • Suggested answer
    SwatiSTW Profile Picture
    714 Super User 2025 Season 2 on 03 Apr 2025 at 11:29:52
    How to parse and use the JSON data that is sent by webhook to a teams channel?
    The problem is that the JSON you want is inside a string field called text, and it includes <pre> tags. So Power Automate can't directly parse it. You need to extract that string, clean it, and parse it again.
    1. First Parse JSON to extract the text field from the incoming webhook
    Schema to use:
        {
          "type": "object",
          "properties": {
            "text": {
              "type": "string"
            }
          }
        }
    2. Add a Compose action to remove <pre> and </pre> from the text
    Expression to use:
        replace(replace(body('Parse_JSON')?['text'], '<pre>', ''), '</pre>', '')
    3. Add a second Parse JSON action, use output from the Compose as input
    Content field:
        outputs('Compose')
    Schema to use:
        {
          "type": "object",
          "properties": {
            "content": { "type": "string" },
            "message": { "type": "string" },
            "time": { "type": "string" },
            "username": { "type": "string" },
            "source IP": { "type": "string" }
          }
        }
    4. In the Teams message action, use dynamic content from the second Parse JSON
    Example message:
        <b>New Log Entry</b><br>
        User: @{outputs('Parse_JSON_2')?['username']}<br>
        Message: @{outputs('Parse_JSON_2')?['message']}<br>
        Time: @{outputs('Parse_JSON_2')?['time']}<br>
        Source IP: @{outputs('Parse_JSON_2')?['source IP']}
    This will show each field correctly in the Teams message.
  • SS-03041020-0 Profile Picture
    12 on 03 Apr 2025 at 12:16:10
    How to parse and use the JSON data that is sent by webhook to a teams channel?
     
    Thank you very much for your reply and your advice - thanks to you I am several steps further.
    Unfortunately, I am still making a mistake along the path as now the second "parse json" fails.
     
    In the "componse" action I only have one single configuration available, which is called "inputs". I put in the expression you mentioned = replace(replace(body('Parse_JSON')?['text'], '<pre>', ''), '</pre>', '').
    However, I have the feeling this wasn't correct on my part.
     
    The error message now reads:
     
    InvalidJSON. The 'content' property of actions of type 'ParseJson' must be valid JSON. The provided value cannot be parsed: 'Unexpected character encountered while parsing value: o. Path '', line 0, position 0.'.
     
     
    And the raw output of the "compose" action reads as follows:
     
    "replace(replace(body('Parse_JSON')?['text'], '<pre>', ''), '</pre>', '')"
     
    Do you have any advice?
     
     
    P.S.:
    The output of the first "parse json" looks extremly promising:
    <pre>{
    "content": "obfuscate".
    "message": "",
    "time": "%%log_time%%",
    "username": "%%log_user%%",
    "source IP": "%%log_srcip%%"
    }</pre>
     
  • Chriddle Profile Picture
    8,339 Super User 2025 Season 2 on 03 Apr 2025 at 14:39:58
    How to parse and use the JSON data that is sent by webhook to a teams channel?
    The JSON within the property "text" is invalid.
    Assuming it is an editing error and after cleaning:
     
     
    Compose: The original JSON
     
    Parse JSON:
    Content:
    json(
    	slice(
    		body('Compose')['text'],
    		5,
    		-6
    	)
    )
    Schema:
    {
        "type": "object",
        "properties": {
            "content": {
                "type": "string"
            },
            "message": {
                "type": "string"
            },
            "time": {
                "type": "string"
            },
            "username": {
                "type": "string"
            },
            "source IP": {
                "type": "string"
            }
        }
    }
     
     
  • SS-03041020-0 Profile Picture
    12 on 04 Apr 2025 at 08:47:21
    How to parse and use the JSON data that is sent by webhook to a teams channel?
    Dear @Chriddle and @SwatiSTW
     
    As suggested by @Chriddle I added another "parse json" action after the "compose" action with the configuraiton that was suggested and with the following result (raw input):
     
    {
        "content": "json(\n\tslice(\n\t\tbody('Compose')['text'],\n\t\t5,\n\t\t-6\n\t)\n)",
        "schema": {
            "type": "object",
            "properties": {
                "content": {
                    "type": "string"
                },
                "message": {
                    "type": "string"
                },
                "time": {
                    "type": "string"
                },
                "username": {
                    "type": "string"
                },
                "source IP": {
                    "type": "string"
                }
            }
        }
    }
     
     
    While I was able to save that flow in power automate, it now gives me the following error message when the flow is triggered:
     
    InvalidJSON
    The 'content' property of actions of type 'ParseJson' must be valid JSON. The provided value cannot be parsed: 'Unexpected character encountered while parsing value: j. Path '', line 0, position 0.'.
     
    It appears that the "content" part of the second "parse json" can't be a json slice operation? Or am I missing some special flag needed for the slice json operation to be valid in the "content" part of the "parse json" action?
     
    Again, the output of the compose is promising (it just has the <pre> tags still in it):
     
     
    "<pre>{\n \"content\": \"AdminLogin on Fortigate\".\n \"message\": \"\",\n \"time\": \"%%log_time%%\",\n \"username\": \"%%log_user%%\",\n \"source IP\": \"%%log_srcip%%\"\n}</pre>"
     
     
  • Verified answer
    Chriddle Profile Picture
    8,339 Super User 2025 Season 2 on 07 Apr 2025 at 10:06:56
    How to parse and use the JSON data that is sent by webhook to a teams channel?
    The problem is that the text isn't valid JSON.
    Instead of a comma, there's a period.
     
    I fixed this in advance in last week's proposed solution.
     
     
    Can you fix the input?
  • SS-03041020-0 Profile Picture
    12 on 07 Apr 2025 at 11:59:54
    How to parse and use the JSON data that is sent by webhook to a teams channel?
     
    Please accept my sincere apologies - you are absolutely right and I have missed that in your post.
     
    I corrected the input (I indeed made a typo - should have been a comma) and from there things look amazingly better with all your input.
     
    Thanks to you I am busy with finetuning, but not with troubleshooting anymore.
     
    To all, thanks a lot for your help - it is very much appreciated

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Chiara Carbone – Community Spotlight

We are honored to recognize Chiara Carbone as our Community Spotlight for November…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 655 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 371 Moderator

#3
chiaraalina Profile Picture

chiaraalina 276

Last 30 days Overall leaderboard
Loading started
Loading complete