我收到的 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逻辑应用
:
我定义了一个json字符串作为输入:
您可以使用Parse JSON action要解析 JSON,您可以单击使用示例有效负载生成架构
并将 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"
}
]
关于azure-logic-apps - 使用逻辑应用程序根据大量对象中的字段编写新的 JSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65258651/