0

通过 Azure APIM 中的液体模板,我想将下面的 json 转换为不同的输出,仅从'data' 元素中获取某些值,例如 'GROUP(tranid)'

示例 JSON

{
    "result_error": false,
    "result_errorDescription": "",
    "saved_search": "customsearch_int_package_info",
    "page_size": 1000,
    "page_index": "0",
    "total_pages": 1,
    "columns": [
        "numbertext"
    ],
    "joins": "",
    "operators": [
        "haskeywords"
    ],
    "filters": [
        "IF123820"  
    ],
    "data": [
        {
            "values": {
                "GROUP(tranid)": "IF123820",
                "GROUP(createdFrom.tranid)": "SOAU100577",
                "GROUP(CUSTRECORD_BGB_TNX_NUMBER.custrecord_bgb_box_number)": "- None -",
                "GROUP(CUSTRECORD_BGB_TNX_NUMBER.custrecord_bgb_package_tracking_number)": "SHYIZ00048446001",
                "GROUP(CUSTRECORD_BGB_TNX_NUMBER.custrecord_bgb_package_volume)": ".0016",
                "GROUP(CUSTRECORD_BGB_TNX_NUMBER.custrecord_bgb_package_weight)": "1",
                "GROUP(CUSTRECORD_BGB_TNX_NUMBER.custrecord_bgb_package_length)": "40",
                "GROUP(CUSTRECORD_BGB_TNX_NUMBER.custrecord_bgb_package_width)": "20",
                "GROUP(CUSTRECORD_BGB_TNX_NUMBER.custrecord_bgb_package_height)": "2",
                "GROUP(CUSTRECORD_BGB_TNX_NUMBER.externalid)": [
                    {
                        "value": "__RANDOM_ID__455307",
                        "text": "- None -"
                    }
                ]
            }
        }
    ]
}

我为 APIM 编写了以下模板;除了价值下列出的记录外,它工作正常。如何从该部分获取特定值,例如“GROUP(tranid)”中的“IF123820”?

这是我的液体模板(到目前为止我尝试了一些调用):

{
     "saved_search": "{{body.saved_search}}",
     "page_size": "{{body.page_size}}",
     "Status": "Success",
     "Message": "PackageDetails successfully found",
     "Filters":  "{{body.filters}}",
     " Test1 " : {{body.data[0].values.GROUP(tranid)}},
     " body.data ": {{body.data[0]}} ,
     "Package": 
             {% for item in body.data %}
                {% for item2 in item.values %}
                    "Test2": "{{item[0]}}",
                    "Test3": "{{item.GROUP(tranid)}}",
                    "Test4": "{{item2}}",
                    "Test5": {{item[0].GROUP(tranid)}},
                    "Test6": {{item[0]values[GROUP(tranid)]}},
                }
                {% endfor %}

            {% endfor %}


 }

似乎只能从“data.values”部分检索所有记录或通过第二个循环检索单个值;但这并不能解决我仅检索特定记录的问题。

这是我通过上面的模板得到的部分结果:

“……

{
        "saved_search": "customsearch_int_package_info",
        "page_size": "1000",
        "Status": "Success",
        "Message": "PackageDetails successfully found",
        "Filters": "IF123820",
        " Test1 ": ,
        " body.data ": "values": {
            "GROUP(tranid)": "IF123820",
            "GROUP(createdFrom.tranid)": "SOAU100577",
            "GROUP(CUSTRECORD_BGB_TNX_NUMBER.custrecord_bgb_box_number)": "- None -",
            "GROUP(CUSTRECORD_BGB_TNX_NUMBER.custrecord_bgb_package_tracking_number)": "SHYIZ00048446001",
            "GROUP(CUSTRECORD_BGB_TNX_NUMBER.custrecord_bgb_package_volume)": ".0016",
            "GROUP(CUSTRECORD_BGB_TNX_NUMBER.custrecord_bgb_package_weight)": "1",
            "GROUP(CUSTRECORD_BGB_TNX_NUMBER.custrecord_bgb_package_length)": "40",
            "GROUP(CUSTRECORD_BGB_TNX_NUMBER.custrecord_bgb_package_width)": "20",
            "GROUP(CUSTRECORD_BGB_TNX_NUMBER.custrecord_bgb_package_height)": "2",
            "GROUP(CUSTRECORD_BGB_TNX_NUMBER.externalid)": [{
                "value": "__RANDOM_ID__455307",
                "text": "- None -"
            }]
        },
        "Package":


            "Test2": "{
        "GROUP(tranid)": "IF123820",
        "GROUP(createdFrom.tranid)": "SOAU100577",
        "GROUP(CUSTRECORD_BGB_TNX_NUMBER.custrecord_bgb_box_number)": "- None -",
        "GROUP(CUSTRECORD_BGB_TNX_NUMBER.custrecord_bgb_package_tracking_number)": "SHYIZ00048446001",
        "GROUP(CUSTRECORD_BGB_TNX_NUMBER.custrecord_bgb_package_volume)": ".0016",
        "GROUP(CUSTRECORD_BGB_TNX_NUMBER.custrecord_bgb_package_weight)": "1",
        "GROUP(CUSTRECORD_BGB_TNX_NUMBER.custrecord_bgb_package_length)": "40",
        "GROUP(CUSTRECORD_BGB_TNX_NUMBER.custrecord_bgb_package_width)": "20",
        "GROUP(CUSTRECORD_BGB_TNX_NUMBER.custrecord_bgb_package_height)": "2",
        "GROUP(CUSTRECORD_BGB_TNX_NUMBER.externalid)": [{
            "value": "__RANDOM_ID__455307",
            "text": "- None -"
        }]
    }
    ",
    "Test3": "",
    "Test4": "IF123820",
    "Test5": ,
    "Test6": ,
}

"Test2": "{
"GROUP(tranid)": "IF123820",
"GROUP(createdFrom.tranid)": "SOAU100577",
"GROUP(CUSTRECORD_BGB_TNX_NUMBER.custrecord_bgb_box_number)": "- None -",
"GROUP(CUSTRECORD_BGB_TNX_NUMBER.custrecord_bgb_package_tracking_number)": "SHYIZ00048446001",
"GROUP(CUSTRECORD_BGB_TNX_NUMBER.custrecord_bgb_package_volume)": ".0016",
"GROUP(CUSTRECORD_BGB_TNX_NUMBER.custrecord_bgb_package_weight)": "1",
"GROUP(CUSTRECORD_BGB_TNX_NUMBER.custrecord_bgb_package_length)": "40",
"GROUP(CUSTRECORD_BGB_TNX_NUMBER.custrecord_bgb_package_width)": "20",
"GROUP(CUSTRECORD_BGB_TNX_NUMBER.custrecord_bgb_package_height)": "2",
"GROUP(CUSTRECORD_BGB_TNX_NUMBER.externalid)": [{
    "value": "__RANDOM_ID__455307",
    "text": "- None -"
}]
}
",
"Test3": "",
"Test4": "SOAU100577",
"Test5": ,
"Test6": ,
}

"Test2": "{
"GROUP(tranid)": "IF123820",
"GROUP(createdFrom.tranid)": "SOAU100577",
"GROUP(CUSTRECORD_BGB_TNX_NUMBER.custrecord_bgb_box_number)": "- None -",
"GROUP(CUSTRECORD_BGB_TNX_NUMBER.custrecord_bgb_package_tracking_number)": "SHYIZ00048446001",
"GROUP(CUSTRECORD_BGB_TNX_NUMBER.custrecord_bgb_package_volume)": ".0016",
"GROUP(CUSTRECORD_BGB_TNX_NUMBER.custrecord_bgb_package_weight)": "1",
"GROUP(CUSTRECORD_BGB_TNX_NUMBER.custrecord_bgb_package_length)": "40",
"GROUP(CUSTRECORD_BGB_TNX_NUMBER.custrecord_bgb_package_width)": "20",
"GROUP(CUSTRECORD_BGB_TNX_NUMBER.custrecord_bgb_package_height)": "2",
"GROUP(CUSTRECORD_BGB_TNX_NUMBER.externalid)": [{
    "value": "__RANDOM_ID__455307",
    "text": "- None -"
}]
}
",
"Test3": "",
"Test4": "- None -",
"Test5": ,
"Test6": ,
}

……”

欢迎任何解决此问题的建议:-)

4

1 回答 1

0

最后但并非最不重要的是,我找到了答案。此液体代码用于检索值:

"Package": {
             {% for item in body.data %}

                "OrderNumber" : "{{item.values["GROUP(createdFrom.tranid)"]}}",
                "BoxNumber" : "{{item.values["GROUP(CUSTRECORD_BGB_TNX_NUMBER.custrecord_bgb_box_number)"]}}",
                "TrackingNumber" : "{{item.values["GROUP(CUSTRECORD_BGB_TNX_NUMBER.custrecord_bgb_package_tracking_number)"]}}",
                "PackageWeight" : "{{item.values["GROUP(CUSTRECORD_BGB_TNX_NUMBER.custrecord_bgb_package_weight)"]}}"
                

            {% endfor %}
}
于 2021-10-15T15:34:14.330 回答