Do you want to convert string to object format in Power Automate? In this Power Automate tutorial, we will see how to convert a string to an object in Power Automate.
While working with Power Automate, you have the json string data, and you want to convert it into json objects. So, you can use those data in your flow in Power Automate.
To convert json string to json object, we can use JSON(). The JSON() will take the value as a string and convert it into a Json object.
Syntax
JSON(<string>)
Here, we will cover the topics below:
- How to convert string to object in Power Automate.
- How to convert string to object in Power Automate dynamically
Convert string to object in Power Automate
Here, we will see how to convert a string to an object in Power Automate.
Example 1: Convert string to object in Power Automate
Let’s say we have a string ‘GradyArchie – gradyA@email.com, and you need to convert it into json format, i.e. { “name”: “GradyArchie”, “email”: “gradyA@email.com”}. For this, follow the below steps to achieve it.
1. Open Power Automate Cloud, then click on +Create -> select Instant Cloud Flow.
Then, provide a flow name and select the “Manually trigger a flow” action. Then click on Create.
Now, you can see a Manual trigger a flow action is added to the flow page.
2. We will initialize a string variable; for this, click on +New step -> select Initialize variable action. Then provide the information below:
- Name: Provide the name of the variable
- Type: Provide the type as a string
- Value: Provide the value like below
3. We will split the string into two parts; for this, click on Add an action -> select Compose action. Then provide the below information:
- Inputs: Provide the below expression:
split(variables('varStr'), '-')
4. Now, we will convert the string to an object in Power Automate. For this, click on +New step -> select Compose action. Then provide the below information:
Inputs: Provide the below expression:
{
"Topic": "@{outputs('Compose')[0]}",
"Content":"@{outputs('Compose')[1]}"
}
5. Then click on save and run the flow manually; you can see the string is converted to an object in Power Automate.
Example 2: Convert JSON string to object in Power Automate
Let’s say you have json string i.e., ‘{ “name”: “GradyArchie”, “email”: “gradyA@email.com”},’ and we will convert it into json objects { “name”: “GradyArchie”, “email”: “gradyA@email.com”}, for this follow the below steps:
1. Open Power Automate Cloud, then click on +Create -> select Instant Cloud Flow.
Then, provide a flow name and select Manually trigger a flow action. Then click on Create.
Now, you can see a manual trigger a flow action is added to the flow page.
2. We will initialize a string variable; for this, click on +New step -> select Initialize variable action. Then provide the below information:
- Name: Provide the name of the variable
- Type: Provide the type as a string
- Value: Provide the value like below
3. Now, we will convert the string to an object in Power Automate; for this, click on the +New step -> select Compose action. Then provide the below information:
- Inputs: Provide the below expression:
json(variables('varStr'))
4. Now save the flow and run the flow manually; you can see the string is converted to objects in Power Automate.
This is how to convert string to object in Power Automate.
Convert string to object in Power Automate dynamically
Here, we will see how to convert a string to an object from the SharePoint list dynamically in Power Automate.
For example, I have a SharePoint list called Emails, which contains two columns Title (Single line of text) and Email body(Single line of text).
We will take the Email body string, and we will convert it into an object like ‘ {“Event name”: ” Power Automate Session”}’. To achieve it, follow the below steps.
1. Open Power Automate Cloud, then click on +Create -> select Instant Cloud Flow.
Then, provide a flow name and select Manually trigger a flow action. Then click on Create.
Now, you can see a manual trigger a flow action is added to the flow page.
2. We will get items from the SharePoint list; for this, click on the +New step and select the ‘Get items’ action. Then provide the information below
- Site address: Provide the SharePoint site address.
- List name: Provide the Sharepoint list name
3. Next, we will convert the string to an array; for this, click on +New step -> select Compose action. Then provide the below information:
- Inputs: Provide the below expression. It will automatically add Apply to each action.
split(items('Apply_to_each')?['Emailbody'], ':')
4. We will convert it into an object; for this, click on +New step -> select Compose action. Then provide the below information:
- Inputs: Provide the below expression:
{
"Event name": "outputs('Compose')[1]"
}
5. Now save the flow and run the flow manually, and you can see the converted string to an object.
This is how to convert a string to an object dynamically in Power Automate.
Conclusion
In this Power Automate tutorial, we saw how to convert a string to an object in Power Automate.
You may like the following tutorials:
- Convert an Integer to an Array in Power Automate
- Convert Value to String in Power Automate
- Convert String to Date for SharePoint list using Power Automate
I am Bijay a Microsoft MVP (10 times – My MVP Profile) in SharePoint and have more than 17 years of expertise in SharePoint Online Office 365, SharePoint subscription edition, and SharePoint 2019/2016/2013. Currently working in my own venture TSInfo Technologies a SharePoint development, consulting, and training company. I also run the popular SharePoint website EnjoySharePoint.com