Understanding the setProperty() Expression in Power Automate (With Examples)

What is setProperty() in Power Automate?

setProperty() is a function in Power Automate that helps you add a new value or update an existing value in a JSON object. It allows you to change a specific field without rebuilding the entire object.

Syntax

setProperty(object, 'propertyName', value)

Why setProperty() Needs

Before setProperty(), updating a JSON object was difficult. You had to

  • Rebuild the entire object manually

  • Use multiple Compose actions

  • Write complex expressions that were hard to understand and maintain

With setProperty()

  • Updating objects becomes simple and clean

  • Expressions are easier to read

  • Flows are easier to manage and maintain

Example 1: Updating an Object Property

Initial Object

{
  "Name": "Krish",
  "Role": "Developer"
}

Expression

setProperty(variables('UserObject'), 'Role', 'Senior Developer')

Output

{
  "Name": "Krish",
  "Role": "Senior Developer"
}

Explanation

In the Example 1, setProperty() updates the Role from Developer to Senior Developer without changing the rest of the object.

Example 2: Adding a New Property

If the property does not already exist, setProperty() will create it.

Initial Object

{
  "Name": "Krish",
  "Role": "Developer"
}

Expression

setProperty(variables('UserObject'), 'Location', 'India')

Output

{
  "Name": "Krish",
  "Role": "Developer",
  "Location": "India"
}

Explanation

In the Example 2, setProperty() adds a new field called Location with the value India to the existing object.

Conclusion

setProperty() is a very useful function in Power Automate, but many people don’t use it. It makes working with JSON objects much easier by helping you update or add values without extra effort. It also makes your flows cleaner, easier to read, and easier to maintain.