cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
ampetrushenko
New Member

Change propery in JSON with array inside

I have json with like this:

{
"actions": {
"Initialize_variable": {
"runAfter": {},
"type": "InitializeVariable",
"inputs": {
"variables": [
{
"name": "Parameter1",
"type": "String",
"value": "Value1"
}
]
}
}
}
}

 

How can I change the value of "value" field? For example from "Value1" to "Value2", I can change another properties of JSON using setProperty(), but I can't use this for the property in array:(

1 ACCEPTED SOLUTION

Accepted Solutions

Hi @v-litu-msft 

 

Thank you for answer!

Nice try:)

 

But this solution return json without array:(
JSON in Test variable :
{
"actions": {
"Initialize_variable": {
"runAfter": {},
"type": "InitializeVariable",
"inputs": {
"variables": [
{
"name": "Parameter1",
"type": "String",
"value": "Value1"
}
]
}
}
}
}

JSON in Compose Output:
{
"actions": {
"Initialize_variable": {
"runAfter": {},
"type": "InitializeVariable",
"inputs": {
"variables": {
"name": "Parameter1",
"type": "String",
"value": "Value2"
}
}
}
}
}

In my case JSON is a Flow Definition JSON, where "variables" should contain an array.

View solution in original post

4 REPLIES 4
v-litu-msft
Community Support
Community Support

Hi @ampetrushenko,

 

You can check the setProperty() function Example 2 to learn how to set child property for parent property in a JSON object, this is workaround how to set the value to Value2:

 

setProperty(variables('Test'),'actions',setProperty(variables('Test')['actions'],'Initialize_variable',setProperty(variables('Test')['actions']['Initialize_variable'],'inputs',setProperty(variables('Test')['actions']['Initialize_variable']['inputs'],'variables', setProperty(variables('Test')['actions']['Initialize_variable']['inputs']['variables'][0],'value','Value2')))))

 

Annotation 2019-11-28 133004.png

Best Regards,
Community Support Team _ Lin Tu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi @v-litu-msft 

 

Thank you for answer!

Nice try:)

 

But this solution return json without array:(
JSON in Test variable :
{
"actions": {
"Initialize_variable": {
"runAfter": {},
"type": "InitializeVariable",
"inputs": {
"variables": [
{
"name": "Parameter1",
"type": "String",
"value": "Value1"
}
]
}
}
}
}

JSON in Compose Output:
{
"actions": {
"Initialize_variable": {
"runAfter": {},
"type": "InitializeVariable",
"inputs": {
"variables": {
"name": "Parameter1",
"type": "String",
"value": "Value2"
}
}
}
}
}

In my case JSON is a Flow Definition JSON, where "variables" should contain an array.

View solution in original post

Any suggestions?:(

I've found a way. 

You need to add the function createArray() that contain the setProperty() to keep the array type

 

Like that:

setProperty(variables('Test'),'actions',setProperty(variables('Test')['actions'],'Initialize_variable',setProperty(variables('Test')['actions']['Initialize_variable'],'inputs',setProperty(variables('Test')['actions']['Initialize_variable']['inputs'],'variables', createArray(setProperty(variables('Test')['actions']['Initialize_variable']['inputs']['variables'][0],'value','Value2'))))))

 

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Top Solution Authors
Top Kudoed Authors
Users online (1,682)