#azure #liquid #azure-policy #apim
Вопрос:
С помощью шаблона liquid в Azure APIM я хочу преобразовать нижеприведенный json в другой вывод, взяв только определенные значения из элемента «данные», например «ГРУППА(идентификатор)».:
Пример 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″ из » ГРУППЫ(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 %}
}
Кажется, что можно извлечь все записи только из раздела «данные.значения» или извлечь отдельные значения через второй цикл; но это не решает мою проблему с извлечением только определенной записи.
Вот часть результата, который я получаю с помощью шаблона выше:
«…
{
"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": ,
}
…»
Любые предложения по решению этой проблемы приветствуются 🙂
Ответ №1:
И последнее, но не менее важное: я нашел ответ. Этот жидкий код работал для извлечения значений :
"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 %}
}