Support Questions
Find answers, ask questions, and share your expertise

Need urgent help with Jolt Transformation

Highlighted

Need urgent help with Jolt Transformation

Explorer

I have been trying to transform the following JSON

 

 

{
  "controlid": "65363_738_VI",
  "MSH_1.AcceptAcknowledgementType": "AL",
  "MSH_1.SendingFacility.NamespaceID": "6",
  "MSH_1.SendingApplication.NamespaceID": "HOSP",
  "MSH_2.AcceptAcknowledgementType": "AK",
  "MSH_2.SendingFacility.NamespaceID": "7",
  "MSH_2.SendingApplication.NamespaceID": "HOSP"
}

 

 

 

 

I am looking for output like

 

 

 

{
  "msh" : [{
    "controlid" : "65363_738_VI",
    "seq" : "1",
    "AcceptAcknowledgementType" : "AL",
    "SendingFacility.NamespaceID" : "6",
    "SendingApplication.NamespaceID" : "HOSP"
  },
{
    "controlid" : "65363_738_VI",
    "seq" : "2"
    "AcceptAcknowledgementType" : "AK" ,
    "SendingFacility.NamespaceID" : "7" ,
    "SendingApplication.NamespaceID" : "HOSP" 
  }
}

 

 

I had the spec as 

 

 

[
  {
    "operation": "shift",
    "spec": {
      "controlid": "msh.&(0,0)",
      "*.*": {
        "@0": "msh.&(0,2)"
      }
    }
  }
]

 

 

 The final output I got was 

 

 

{
  "msh" : {
    "controlid" : "65363_738_VI",
    "AcceptAcknowledgementType" : [ "AL", "AK" ],
    "SendingFacility.NamespaceID" : [ "6", "7" ],
    "SendingApplication.NamespaceID" : [ "HOSP", "HOSP" ]
  }
}

 

 

 

2 REPLIES 2
Highlighted

Re: Need urgent help with Jolt Transformation

Explorer

To add .. The example shows 2 sequences, but there could be many more .. I am planning to put data in Kudu in table and need to put down each sequence combination as a row.

Highlighted

Re: Need urgent help with Jolt Transformation

Contributor

Hi @GKrishan !

[
{
"operation": "shift",
"spec": {
"MSH_*.*": {
"@": "msh_&(1,1).&(1,2)"
},
"*": "root.&"
}
},
{
"operation": "shift",
"spec": {
"msh_*": {
"$(0,1)": "&1.seq",
"@(1,root)": {
"*": "&2.&"
},
"*": "&1.&"
}
}
},
{
"operation": "shift",
"spec": {
"*": "msh"
}
}
]

This spec converts

{
 "name": "adwad",
 "controlid": "65363_738_VI",
 "MSH_1.AcceptAcknowledgementType": "AL",
 "MSH_1.SendingFacility.NamespaceID": "6",
 "MSH_1.SendingApplication.NamespaceID": "HOSP",
 "MSH_2.AcceptAcknowledgementType": "AK",
 "MSH_2.SendingFacility.NamespaceID": "7",
 "MSH_2.SendingApplication.NamespaceID": "HOSP"
}

to


{
 "msh" : [ {
  "seq" : "1",
  "name" : "adwad",
  "controlid" : "65363_738_VI",
  "AcceptAcknowledgementType" : "AL",
  "SendingFacility.NamespaceID" : "6",
  "SendingApplication.NamespaceID" : "HOSP"
 }, {
  "seq" : "2",
  "name" : "adwad",
  "controlid" : "65363_738_VI",
  "AcceptAcknowledgementType" : "AK",
  "SendingFacility.NamespaceID" : "7",
  "SendingApplication.NamespaceID" : "HOSP"
 } ]
}

meaning, whatever attributes are present in the input json, other than MSH_....., will be added to the final output json.
If only, controlid is required, you can use the following spec:

[
 {
"operation": "shift",
"spec": {
"MSH_*.*": {
"@": "msh_&(1,1).&(1,2)"
},
"*": "&"
}
},
{
"operation": "shift",
"spec": {
"msh_*": {
"$(0,1)": "&1.seq",
"@(1,controlid)": "&1.controlid",
"*": "&1.&"
}
}
},
{
"operation": "shift",
"spec": {
"*": "msh"
  }
 }
]
Don't have an account?