Azure Liquid 模板 - 如何从 Apim 策略中的嵌套 json 获取特定值
Azure Liquid template - how to get specifc value from nested json in Apim policy
通过 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 编写了以下模板;除了价值下列出的记录外,它工作正常。如何获取特定值
从那个部分,例如'IF123820' 来自 'GROUP(tranid)'?
这是我的液体模板(到目前为止我尝试了一些调用):
{
"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": ,
}
...
欢迎提出解决此问题的任何建议:-)
最后但同样重要的是我找到了答案。此液体代码用于检索值:
"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 %}
}
通过 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 编写了以下模板;除了价值下列出的记录外,它工作正常。如何获取特定值 从那个部分,例如'IF123820' 来自 'GROUP(tranid)'?
这是我的液体模板(到目前为止我尝试了一些调用):
{
"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": ,
}
...
欢迎提出解决此问题的任何建议:-)
最后但同样重要的是我找到了答案。此液体代码用于检索值:
"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 %}
}