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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Determine if string is...
Power Automate
Answered

Determine if string is an object

(0) ShareShare
ReportReport
Posted on by

I am using an API that sometimes responds with a body of type string, and other times with a body object with some properties. I am first trying to determine which one was returned. If it is a string, I craft an object to return to the parent script.

 

My thought was to try to treat the value as an object and handle failures. e.g. this Set Variable action is set to 

 

json( triggerBody()?['text'] )

 

tekhnik_0-1718598300908.png

 

However, the entire flow is considered as failed even though the error is handled

tekhnik_1-1718598437638.png


I've also tried with Compose to see if it was the type of action - same issue. I've also tried to generate failures with alternate expressions to see if they were handled differently. e.g. 

 

addProperty( triggerBody()?['text'], 'X', 1 )

 

 
However, they all end up making the entire flow get flagged as a failure.

Categories:
  • Verified answer
    v-xiaochen-msft Profile Picture
    Microsoft Employee on at

    Hi @tekhnik ,

     

    Please try this

    vxiaochenmsft_0-1718599648593.png

    vxiaochenmsft_1-1718599656661.png

     

    Best Regards,

    Wearsky

  • Nived_Nambiar Profile Picture
    18,138 Super User 2026 Season 1 on at

    Hi @tekhnik 

     

    I think you have set the api either to give response in format or application/json or text/html which causes its response to be in JSON or HTML .

     

    To identify whether it is json or html string. I would recommend these two conditons

     

    to check whether it is json string use following expression

    startsWith(string(triggerBody()?['text']),'{')

     

    to check whether it starts with HTML

    startsWith(string(triggerBody()?['text']),'<html>')

     

    When designed in flow - you can try like this

    Nived_Nambiar_0-1718600182214.png

     

     

    Hope it helps !

    Thanks & Regards,

    Nived N 🚀

    LinkedIn: Nived N's LinkedIn
    YouTube: Nived N's YouTube Channel
    Blog: Nived Nambiar's Blogs

    🔍 Found my answer helpful? Please consider marking it as the solution!
    Your appreciation keeps me motivated. Thank you! 🙌

     

  • tekhnik Profile Picture
    on at

    I think you have set the api either to give response in format or application/json or text/html which causes its response to be in JSON or HTML .

    Actually I have not done so. The API is always called with header Accept : application/json. It simply returns both simple strings and objects.

     

    I cannot rely on that same API to always return specific tags, or NOT to return simple strings that begin with a curly brace. That is why I want a more generic method to check if a string can be cast as an object.

     

    The issue I am trying to solve is that the workflow is marked as failed when I do so. Sorry if the title did not make that clear.

  • tekhnik Profile Picture
    on at

    Yes, that did it Wearsky! @v-xiaochen-msft 

    So that I can understand, can you explain or point me to documentation regarding overall flow status?

    I assumed that if a parallel branch handled an error, it would not propagate down. In other words, if Compose2 in your flow was green, the flow should be green. Is the 'override' via Terminate necessary if any failures are encountered?

  • Chriddle Profile Picture
    8,729 Super User 2026 Season 2 on at

    Probably the easiest and cleanest way to handle this is to check the status code in the response header..

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Automate

#1
Mohsin Ali Profile Picture

Mohsin Ali 423

#2
11manish Profile Picture

11manish 308 Super User 2026 Season 2

#3
M Bilal Khan Profile Picture

M Bilal Khan 177

Last 30 days Overall leaderboard