使用逻辑应用程序根据大型对象数组中的字段编写新的 JSON
Compose new JSON based on field in large array of objects with Logic Apps
我收到的 JSON 没有很好地分组。对于在人力资源系统中更新的每个“字段”,我都会收到一个包含许多不必要字段的对象。这些对象只有三个我感兴趣的值,“uniqueId”、“field”和“value”。
[
{
"uniqueId": "Env30362",
"field": "DateOfBirth",
"value": "1980-12-01"
Lots of more unnecessary fields...
},
{
"uniqueId": "Env30362",
"field": "StartDate",
"value": "2020-01-01"
Lots of more unnecessary fields...
},
{
"uniqueId": "Env30363",
"field": "DateOfBirth",
"value": "1980-12-01"
Lots of more unnecessary fields...
},
Lots of objects with different uniqueId…
]
我想获取与 uniqueId 关联的所有“字段”和“值”并创建一个新的 JSON,例如,其中 uniqueId 是 Env30362。
{
"uniqueId": "Env30362",
"StartDate”: "2020-01-01",
"DateOfBirth": "1980-12-01"
etc..
}
如何使用逻辑应用程序实现此目的?
请参考我的azure logic app
:
我定义了一个json字符串作为输入:
您可以使用 Parse JSON action 来解析您的 JSON,您可以单击 Use sample payload to generate schema
并将您的 json 粘贴到其中以生成架构。
定义一个数组,循环获取所有uniqueId
。
您可以使用以下表达式删除多余的uniqueId
。
表达式:
union(variables('uniqueIdArr'),variables('uniqueIdArr'))
循环 uniqueId
数组,然后使用 Filter array action 过滤掉包含相同 uniqueId
.
的项目
表达式:
array(json(variables('jsonString')))
string(item())
body('Filter_array')[2]?['value']
body('Filter_array')[1]?['value']
输入json字符串:
[
{
"uniqueId": "Env30362",
"field": "DateOfBirth",
"value": "1980-12-01",
"test1": "value1"
},
{
"uniqueId": "Env30362",
"field": "StartDate",
"value": "2020-01-01",
"test1": "value2"
},
{
"uniqueId": "Env30363",
"field": "DateOfBirth",
"value": "1980-12-01",
"test1": "value1"
},
{
"uniqueId": "Env30363",
"field": "DateOfBirth",
"value": "1980-12-01",
"test1": "value1"
},
{
"uniqueId": "Env30363",
"field": "StartDate",
"value": "2020-01-01",
"test1": "value2"
},
{
"uniqueId": "Env30362",
"field": "DateOfBirth",
"value": "1980-12-01",
"test1": "value1"
}
]
我收到的 JSON 没有很好地分组。对于在人力资源系统中更新的每个“字段”,我都会收到一个包含许多不必要字段的对象。这些对象只有三个我感兴趣的值,“uniqueId”、“field”和“value”。
[
{
"uniqueId": "Env30362",
"field": "DateOfBirth",
"value": "1980-12-01"
Lots of more unnecessary fields...
},
{
"uniqueId": "Env30362",
"field": "StartDate",
"value": "2020-01-01"
Lots of more unnecessary fields...
},
{
"uniqueId": "Env30363",
"field": "DateOfBirth",
"value": "1980-12-01"
Lots of more unnecessary fields...
},
Lots of objects with different uniqueId…
]
我想获取与 uniqueId 关联的所有“字段”和“值”并创建一个新的 JSON,例如,其中 uniqueId 是 Env30362。
{
"uniqueId": "Env30362",
"StartDate”: "2020-01-01",
"DateOfBirth": "1980-12-01"
etc..
}
如何使用逻辑应用程序实现此目的?
请参考我的azure logic app
:
我定义了一个json字符串作为输入:
您可以使用 Parse JSON action 来解析您的 JSON,您可以单击 Use sample payload to generate schema
并将您的 json 粘贴到其中以生成架构。
定义一个数组,循环获取所有uniqueId
。
您可以使用以下表达式删除多余的uniqueId
。
表达式:
union(variables('uniqueIdArr'),variables('uniqueIdArr'))
循环 uniqueId
数组,然后使用 Filter array action 过滤掉包含相同 uniqueId
.
表达式:
array(json(variables('jsonString')))
string(item())
body('Filter_array')[2]?['value']
body('Filter_array')[1]?['value']
输入json字符串:
[
{
"uniqueId": "Env30362",
"field": "DateOfBirth",
"value": "1980-12-01",
"test1": "value1"
},
{
"uniqueId": "Env30362",
"field": "StartDate",
"value": "2020-01-01",
"test1": "value2"
},
{
"uniqueId": "Env30363",
"field": "DateOfBirth",
"value": "1980-12-01",
"test1": "value1"
},
{
"uniqueId": "Env30363",
"field": "DateOfBirth",
"value": "1980-12-01",
"test1": "value1"
},
{
"uniqueId": "Env30363",
"field": "StartDate",
"value": "2020-01-01",
"test1": "value2"
},
{
"uniqueId": "Env30362",
"field": "DateOfBirth",
"value": "1980-12-01",
"test1": "value1"
}
]