Manipulate JSON objects or arrays: using setProperty/addProperty
Aug 23, 2025 • 3 • 540
Table of contents
In Power Automate, working with JSON objects and arrays is essential for building advanced, scalable, and maintainable flows. JSON acts as the backbone of data exchange, allowing you to represent structured information flexibly.
Two powerful expressions—setProperty()
and addProperty()
—unlock the ability to dynamically update, expand, and manipulate JSON objects.
This article explores what these functions do, why they matter, and how you can apply them in real-world automation scenarios.
Why Manipulate JSON in Power Automate?
Before diving into the syntax, let’s answer the bigger question: why bother manipulating JSON at all?
- Dynamic Data: APIs, forms, and connectors typically return JSON. Mastering it means fewer conversion headaches.
- Reduced Complexity: One JSON object can replace dozens of separate variables.
- Flexibility: Modify or extend data structures without reworking the entire flow.
- API Call Optimization: Fewer variable initialization actions mean fewer API calls and better performance.
💡 For example: if you start a flow with multiple input parameters and create a separate variable for each one, every initialization counts as an API call. Instead, you can group them all into a single object add a Parse JSON to define schema and manage them with setProperty()
or addProperty()
.
Understanding setProperty() and addProperty()
1. setProperty()
The setProperty()
expression updates an existing property.
Syntax:
setProperty(<object>, <propertyName>, <value>)
<object>
– The original JSON object<propertyName>
– The property to set or update<value>
– The new value
When to use:
- Overwriting existing values (e.g., updating an email address)
- Adding new properties in a controlled way
2. addProperty()
The addProperty() expression adds a new property to a JSON object without overwriting existing ones. If the property already exists, the function fails (unlike setProperty()).
Syntax:
addProperty(<object>, <propertyName>, <value>)
When to use:
- When you need to append new properties without the risk of overwriting
- Useful for incremental building of objects in complex flows
Example
Example of a JSON object.
Example of a JSON object including data.
Consider the following customer interaction data:
// Sample customer interaction data
{
"customerId": "12345",
"name": "John Doe",
"email": "john@example.com",
"purchase": {
"product": "Smartphone",
"price": 799.99,
"date": "2024-03-17"
}
}
Updating a property with setProperty()
Scenario: The customer updates their email address. You can use the following expression in a Compose action:
setProperty(variables('CustomerProfile'), 'email', variables('CustomerData')?['email'])
Output displays the updated email value:
Result: The email property is updated while everything else remains untouched.
Adding a nested element with addProperty()
Scenario: You want to add a product field under purchase. Which will make it easier for use to refer in later actions.
addProperty(variables('CustomerProfile'),'purchase',variables('CustomerData')?['purchase']?['product'])
Output displays the product value:
Working with Parse JSON Action
While manipulating JSON objects is powerful, you’ll often need to access properties individually in other steps. This is where Parse JSON comes in:
- Input: Provide your raw JSON
- Schema: Auto-generate or define it manually
- Benefit: Use dynamic content directly without extra variables
⚠️ Important: If you add or remove properties, you must update the schema in the Parse JSON action to prevent runtime errors.
Conclusion
By mastering setProperty() and addProperty(), you can build flows that are:
- Dynamic – adapting to changing data
- Efficient – fewer API calls and variables
- Maintainable – cleaner, scalable structures
Instead of managing endless variables, think in JSON. With these two expressions, your flows become more robust, future-proof, and easier to maintain.