逻辑应用程序:在 Json 对象数组中查找元素(如 XPath fr XML)
Logic App : Finding element in Json Object array (like XPath fr XML)
在我的逻辑应用程序中,我有一个 JSON 对象(从 API 响应中解析)并且它包含一个对象数组。
如何根据属性值找到特定元素...下面的示例我想在其中找到(第一个)活动元素
{
"MyList" : [
{
"Descrip" : "This is the first item",
"IsActive" : "N"
},
{
"Descrip" : "This is the second item",
"IsActive" : "N"
},
{
"Descrip" : "This is the third item",
"IsActive" : "Y"
}
]
}
您可以使用 Parse JSON 任务来解析您的 JSON 和 Condition 来过滤IsActive
属性:
使用以下 Schema 解析 JSON:
{
"type": "object",
"properties": {
"MyList": {
"type": "array",
"items": {
"type": "object",
"properties": {
"Descrip": {
"type": "string"
},
"IsActive": {
"type": "string"
}
},
"required": [
"Descrip",
"IsActive"
]
}
}
}
}
这是它的样子(我包含了您提供的示例数据来测试它):
然后可以添加条件:
并在 If true 部分中执行您想要的任何操作。
嗯...答案显而易见...有一个 FILTER ARRAY 操作,它作用于 JSON 对象(来自 PARSE JSON action).. 将其与 @first()
表达式结合使用将给出所需的结果。
在我的逻辑应用程序中,我有一个 JSON 对象(从 API 响应中解析)并且它包含一个对象数组。
如何根据属性值找到特定元素...下面的示例我想在其中找到(第一个)活动元素
{
"MyList" : [
{
"Descrip" : "This is the first item",
"IsActive" : "N"
},
{
"Descrip" : "This is the second item",
"IsActive" : "N"
},
{
"Descrip" : "This is the third item",
"IsActive" : "Y"
}
]
}
您可以使用 Parse JSON 任务来解析您的 JSON 和 Condition 来过滤IsActive
属性:
使用以下 Schema 解析 JSON:
{
"type": "object",
"properties": {
"MyList": {
"type": "array",
"items": {
"type": "object",
"properties": {
"Descrip": {
"type": "string"
},
"IsActive": {
"type": "string"
}
},
"required": [
"Descrip",
"IsActive"
]
}
}
}
}
这是它的样子(我包含了您提供的示例数据来测试它):
然后可以添加条件:
并在 If true 部分中执行您想要的任何操作。
嗯...答案显而易见...有一个 FILTER ARRAY 操作,它作用于 JSON 对象(来自 PARSE JSON action).. 将其与 @first()
表达式结合使用将给出所需的结果。