How to Convert String to Object in Power Automate

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.

power automate convert string to json

Then, provide a flow name and select the “Manually trigger a flow” action. Then click on Create.

 convert string to json in power automate

Now, you can see a Manual trigger a flow action is added to the flow page.

Power Automate convert string to object

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
Microsoft Power Automate convert string to object

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'), '-')
 convert string to object Microsoft Power Automate

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:

See also  Power Automate Multiple Conditions [With 19 useful examples]

Inputs: Provide the below expression:

{
"Topic": "@{outputs('Compose')[0]}",
"Content":"@{outputs('Compose')[1]}"
}
convert string to object in Microsoft Power Automate

5. Then click on save and run the flow manually; you can see the string is converted to an object in Power Automate.

How to convert string to object in Microsoft 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.

power automate convert string to json

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.

Power Automate convert string to object

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
How to convert string to object Microsoft Power Automate

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'))
How to convert string to object Power Automate

4. Now save the flow and run the flow manually; you can see the string is converted to objects in Power Automate.

How to convert string to object in Microsoft 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).

See also  How to Copy Data from One Excel to Another Excel in Power Automate?
convert string to object Power Automate

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.

power automate convert string to json

Then, provide a flow name and select Manually trigger a flow action. Then click on Create.

 convert string to json in power automate

Now, you can see a manual trigger a flow action is added to the flow page.

Power Automate convert string to object

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
convert string to object in Power Automate

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'], ':')
convert string to json power automate

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]"
}
power automate string to object

5. Now save the flow and run the flow manually, and you can see the converted string to an object.

string to json power automate

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:

>