如何在逻辑应用程序中循环并从嵌套 Json 数组中提取项目

How to loop and extract items from Nested Json Array in Logic Apps

我需要从嵌套的 json 数组中提取每个元素。我正在寻找一种方法.. 架构:

{
    "id":"1",
    "name":"One",
    "child":[
        {

            "id":"2",
            "name":"two",
            "child":[]
        },
        {
            "id":"3",
            "name":"three",
            "child":[

                {
                    "id":"4",
                    "name":"four",
                    "child":[]
                },
                {
                    "id":"5",
                    "name":"five",
                    "child":[]
                }

                ]
        }

        ]

}

生成的有效负载需要 {"id":"1","name":"one"},{"id":"2","name":"two"},{"id":"3","name":"three"}

您可能需要编写一个递归函数。在 python 中,它看起来像:

def get_payload(obj):
  ret = [{'id':obj['id'], 'name':obj['name']}]
  for child in obj['child']:
    ret.extend(get_payload(child))

  return ret