简体   繁体   中英

Jolt Json transformation: Using value of an attribute to filter on a key

I am trying to transform a Json Using Jolt transformation looking for some input here. I am trying to filter on a Key which is a value of another attribute. here is my input and expected output

{
    "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"  
}

And the Output i am looking at is

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

and the spec that i tried with is

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

But i am not getting expected output. I tried with few other combination too but failed to get correct output.Can some one please help in this?

[ // 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"
          }
        }
      }
    }
  }
]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM