0

I am trying to update some JSON in a logic app. Here is my JSON.

{
  "headers": [
    {
      "count": 0,
      "lookup": "PSI"
    },
    {
      "count": 0,
      "lookup": "Clean"
    }
  ]
}

In a for each loop, I am trying to update the property count of a specific header array element.

Here is the setproperty I am doing.

@setproperty(variables('colObj'), 'headers', setproperty(items('For_each'), 'count', 1))

Currently, the setproperty only returns one element of the array and not the entire array.

I need the set property to return all elements of the headers array and to update the count property for the current foreach item.

Does anyone know how to do this in a logic app?

1
  • Any process? Could get the output with my way? Commented Sep 18, 2019 at 15:19

1 Answer 1

4

Actually, we already know to set the child property in a child object, use a nested setProperty() call instead. And the items('For_each') is not quiet the child part of json data, it's like variables('colObj')['headers'][0]. And if you try to add one more nested setProperty(), it will say the array is not a object then your way will only get one child array object.

So if you want to get the complete json object you will have to add some actions to implement. Maybe you could refer to my flow.

I use a Parse_json to set the json data it should be your variables('colObj'), one null object variable , one array variable.

enter image description here

In the For_each set the result object with setProperty(body('Parse_JSON'),'headers',setProperty(items('For_each'),'count',34)) then append it to the array. After the For_each action init a new object to get the object you want and set it with setProperty(body('Parse_JSON'),'headers',variables('middle')).

enter image description here

And this is the run details.

enter image description here

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.