Created on
12-16-2019
02:21 PM
- last edited on
12-16-2019
07:44 PM
by
ask_bill_brooks
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" ]
}
}
Created 12-16-2019 02:27 PM
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.
Created 09-21-2020 11:16 AM
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"
}
}
]