【问题标题】:Jolt Json transformation: Using value of an attribute to filter on a keyJolt Json 转换:使用属性的值来过滤键
【发布时间】:2021-04-15 05:47:10
【问题描述】:

我正在尝试使用 Jolt 转换来转换 Json,以在此处寻找一些输入。 我正在尝试过滤作为另一个属性值的键。这是我的输入和预期输出

{
    "pid": "p1@gmail.com",
    "eventType": "new",
    "details": {   
        "participants": {
            "automationqaus@gmail.com": {
                "id": "automationqaus@gmail.com",
                "type": "Customer"
            },
            "p1@gmail.com": {           
                "id": "p1@gmail.com",               
                "name": "participantAgent1",
                "joinTime": 1617634021103, 
                "type":"Agent"              
               
            },
            "p2@gmail.com": {           
                "id": "p2@gmail.com",                
                "name": "participantAgent1",
                "joinTime": 1617634022303,
                "type":"Agent"
                
            }
        }        
    },
    "interactionId": "c5804d49-961d-11eb-9650-7fb32f44d8a5"  
}

我正在查看的输出是

{
    "pid": "p1@gmail.com",      
    "name": "participantAgent1",
    "joinTime": 1617634021103,
    "type":"Agent"
}

我尝试使用的规范是

[
  {
    "operation": "shift",
    "spec": {
      "participants": {
        "@(2,pid)": {
          "@(3,pid)": "pid",
          "pType": "type",
          "name": "name",
          "joinTime":"joinTime"
        }
      }
    }
  }
]

但我没有得到预期的输出。我也尝试了其他几种组合,但未能获得正确的输出。有人可以帮忙吗?

【问题讨论】:

    标签: json jolt


    【解决方案1】:
    [ // converting the matching value as the key to the value of the details.
      {
        "operation": "shift",
        "spec": {
          "details": "@(1,pid)"
        }
      },
      {
        "operation": "shift",
        "spec": {
          "*": {
            "participants": {
                "&1": { // matching with the target converted key
                "id": "pid",
                "type": "type",
                "name": "name",
                "joinTime": "joinTime"
              }
            }
          }
        }
      }
    ]
    

    【讨论】:

    • 非常感谢您的回答。真的很感激。
    猜你喜欢
    • 2022-08-04
    • 2021-10-05
    • 2020-05-09
    • 1970-01-01
    • 1970-01-01
    • 2021-12-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多