azure-logic-apps - 使用逻辑应用程序根据大量对象中的字段编写新的 JSON

标签 azure-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逻辑应用:

我定义了一个json字符串作为输入:

enter image description here

您可以使用Parse JSON action要解析 JSON,您可以单击使用示例有效负载生成架构并将 json 粘贴到其中以生成架构。

enter image description here

定义一个数组以循环获取所有uniqueId

enter image description here

enter image description here

您可以使用以下表达式删除多余的uniqueId

表达式:

union(variables('uniqueIdArr'),variables('uniqueIdArr'))

enter image description here

循环uniqueId数组,然后使用Filter array action过滤掉包含相同 uniqueId 的项目。

表达式:

array(json(variables('jsonString')))

string(item())

body('Filter_array')[2]?['value']

body('Filter_array')[1]?['value']

enter image description here enter image description here

输入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/

相关文章:

architecture - 什么时候应该使用Logic App而不是Web Job?

azure - 如何使用逻辑应用程序从二进制输出将文件另存为 pdf

azure - 在逻辑应用中将电子邮件处理为另一封电子邮件的附件

azure - 为使用 OnPrem 数据网关的 API 连接部署 ARM 模板成功,但缺少 authType 和网关参数

azure - 使用连接器更新 Azure ARM 模板

sql-server - Azure逻辑应用程序,SQL获取具有日期时间比较的行

azure - 我可以删除 Azure 中的本地网关吗?

azure - Azure 逻辑应用(标准)中缺少 "schedule delay"连接器

oracle - Azure 逻辑应用 - Oracle 连接器 - 执行查询

azure - 如何在应用程序逻辑中转换 JSON?