Updating Json Array in LogicApp

别等时光非礼了梦想. 提交于 2021-01-29 18:58:24

问题


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:


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.

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')).

And this is the run details.



来源:https://stackoverflow.com/questions/57895820/updating-json-array-in-logicapp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!