用于在 Azure 逻辑应用程序中将 json 转换为 json 的 Liquid 模板

Liquid templates for transforming json to json in Azure LogicApps

我是这个 Azure 液体模板的新手。我在 json 数组中有六个元素。我正在将 json 解析为 json。

{
          "arrayvalues": [
            {
              "id": 1,
              "tot": 2,
              "vu": "100",
               "props": [
                {
                  "find": "ghi",
                  "sky": "1000"
                },
                {
                  "find": "ijk",
                  "sky": "1"
                }
              ]
            },
            {
              "id": 2,
              "tot": 1,
              "vu": "0",
              "props": [
               {
                  "find": "abc",
                  "sky": "500"
                },
                {
                  "find": "ijk",
                  "sky": "2"
                }
              ]
            },
            {
              "id": 3,
              "tot": 10,
              "vu": "300",
              "props": [
              
                {
                  "find": "abc",
                  "sky": "100"
                },
                {
                  "find": "ijk",
                  "sky": "3"
                }
              ]
            },
            {
              "id": 4,
              "tot": 5,
              "vu": "500",
              "props": [
                {
                  "find": "xyz",
                  "sky": "900"
                },
                {
                  "find": "ijk",
                  "sky": "4"
                }
              ]
            },
            {
              "id": 5,
              "tot": 6,
              "vu": "10000",
              "props": [
                {
                  "find": "xyz",
                  "sky": "00"
                },
                {
                  "find": "ijk",
                  "sky": "5"
                }
              ]
            },
            {
              "id": 6,
              "tot": 7,
              "vu": "20000",
              "props": [
                {
                  "find": "xyz",
                  "sky": "001"
                },
                {
                  "find": "ijk",
                  "sky": "6"
                }
              ]
            }
          ]
        }
  1. 首先我必须检查名为“查找”的字段。如果“查找”值等于“abc”。然后我需要获取“天空”字段值(即 500 和 100(在第二和第三行中))。而且我还需要获取该行项目的“tot”值(即第 2 和第 3 行项目中的“1”和“10”)。

  2. 我需要将此“天空”值与另一个行项目“vu”值映射。如果为真,则输出如下所示(在我们的场景中,第二个 lineitem“sky”值与第 4 个 lineitem“vu”值 500 匹配。第三个 lineitem“sky”值与第一个 lineitem“vu”值匹配 100)。

    { “编号”:“1”, “总计”:“2”, "vu": "100", “马克”:“是的”, “音量”:“10” }, { “编号”:“4”, “总计”:“5”, "vu": "500", “马克”:“是的”, “音量”:“1” }

(我们从第 2 和第 3 行项目“tot”值中获得的“数量”值是 1 和 10)。

3.Here 没有“天空”字段值与第 5 和第 6 行项目“vu”值(即 10000 和 20000)不匹配。所以第 5 行和第 6 行的输出将如下所示:

{
          "id": "5",
          "tot": "6",
          "vu": "10000",
          "Mark": "NO",
          "Volume": "0"
        },
        {
        "id": "6",
          "tot": "7",
          "vu": "20000",
          "Mark": "NO",
          "Volume": "0"
        }

我的总输出如下:

 {
      "arrayvalues": [
        {
         "id": "1",
          "tot": "2",
          "vu": "100",
          "Mark": "Yes",
          "Volume": "10"
        },
        {
          "id": "2",
          "tot": "1",
          "vu": "0",
          "Mark": "NO",
          "Volume": "0"
        },
        {
          "id": "3",
          "tot": "10",
          "vu": "300",
          "Mark": "NO",
          "Volume": "0"
        },
        {
          "id": "4",
          "tot": "5",
          "vu": "500",
          "Mark": "Yes",
          "Volume": "1"
        },
        {
          "id": "5",
          "tot": "6",
          "vu": "10000",
          "Mark": "NO",
          "Volume": "0"
        },
        {
          "id": "6",
          "tot": "7",
          "vu": "20000",
          "Mark": "NO",
          "Volume": "0"
        }
      ]
    }

我试过下面的代码。

{% assign sky_name = "" %}
{% assign tot_value = "" %}
{
  "values": [
    {% for i in content.arrayvalues %}
        {% for properties in i.props %}
            {% if properties.find == "abc" %}
            {
            "id" : "{{i.id}}",
            "tot" : "{{i.tot}}",
            "vu" : "{{i.vu}}",
            "Mark" : "NO",
            "Volume" : "0"
            },
            {% assign sky_name = properties.sky %}
            {% assign tot_value = i.tot %}
            {% endif %}
        {% endfor %}
            {% assign vu_name = i.vu %}
            {% if vu_name == sky_name %}
            {
            "id" : "{{i.id}}",
            "tot" : "{{i.tot}}",
            "vu" : "{{i.vu}}",
            "Mark" : "Yes",
            "Volume" : "{{tot_value}}"
            }
           {% endif %}
    {% endfor %}
]
}

请帮我解决这个问题....

此致, 维杰

请参考我的Azure liquid template:

{% assign sky_name = "" %}
    {% assign tot_value = "" %}
    {
      "values": [
        {% for i in content.arrayvalues %}
            {% for properties in i.props %}
                {% if properties.find == "abc" %}
                {
                "id" : "{{i.id}}",
                "tot" : "{{i.tot}}",
                "vu" : "{{i.vu}}",
                "Mark" : "NO",
                "Volume" : "0"
                },
                {% assign sky_name = properties.sky %}
                {% assign tot_value = i.tot %}
                {% for j in content.arrayvalues %}
                    {% assign vu_name = j.vu %}
                    {% if vu_name == sky_name %}
                    {
                    "id" : "{{j.id}}",
                    "tot" : "{{j.tot}}",
                    "vu" : "{{j.vu}}",
                    "Mark" : "Yes",
                    "Volume" : "{{tot_value}}"
                    },
                    {% endif %}
                {% endfor %}
                {% endif %}
            {% endfor %}
        {% endfor %}
    ]
    }