Jolt Transformation to match on multiple key values - jolt

I'm struggling to find the correct jolt spec to evaluate the values of two keys prior to creating an output. Any ideas?
Input:
{
"ticketInformation": {
"area": "001",
"site": "ABC",
"ticketType": "TC"
}
}
Spec:
[
{
"operation": "shift",
"spec": {
"ticketInformation": {
"area": {
"001": {
"#Works": "OneMatch"
}
},
"ticketType": {
"TC": {
"#OnlyEvaluatingTicketType": "HowToEvalueValuesOfTwoKeys"
}
}
}
}
}
]
Output:
{
"OneMatch" : "Works",
"HowToEvalueValuesOfTwoKeys" : "OnlyEvaluatingTicketType"
}
The desired output is the same as the actual output but ONLY if area=001 AND troubleType=TC.

I guess this is the spec you are looking for
[
{
"operation": "shift",
"spec": {
"ticketInformation": {
"area": {
"001": {
"#(2,ticketType)": {
"TC": {
"#Yes": "BothMatching"
}
}
}
}
}
}
}
]

Related

Jolt Transformation problems with null Elements

I have a problem with my Jolt transformation but no idea how to fix it.
I get "null" Element in the array I produce:
{
"Verkaufsprodukt": [
{
"Produkt": [
{
"Elementarprodukt": [
{
"ArtID": {
"bezeichnung": "b",
"value": "0302"
},
"VersichertePerson": {
"PartnerID": "1"
}
},
{
"ArtID": {
"bezeichnung": "f"
},
"VersichertePerson": {
"PartnerID": "1"
}
},
{
"ArtID": {
"bezeichnung": "c"
},
"VersichertePerson": {
"PartnerID": "1"
}
},
{
"ArtID": {
"bezeichnung": "a",
"value": "0301"
},
"VersichertePerson": {
"PartnerID": "1"
}
}
]
}
]
}
],
"Partner": [
{
"Name": "Holgerson",
"PartnerID": "1",
"Vorname": "Nils"
}
]
}
My result:
{
"vertragsdetails" : {
"versichertePersonen" : {
"versicherungssummenOderLeistungen" : [ null, {
"kennung" : "0302"
}, null, {
"kennung" : "0301"
} ]
}
}
}
Here is my spec:
[
{
"operation": "shift",
"spec": {
"Verkaufsprodukt": {
"*": {
"Produkt": {
"*": {
"Elementarprodukt": {
"*": {
"VersichertePerson": {
"PartnerID": {
"1": {
"#(3)": {
"ArtID": {
"value": "vertragsdetails.versichertePersonen.versicherungssummenOderLeistungen[&6].kennung"
}
}
}
}
}
}
}
}
}
}
}
}
}
]
I see, that the null elements comes from the "ArtID" elements without "vaules" but how can I get rid of them?
I tried a '"operation": "shift",' but that deleted also other elements I want to have.
Can somebody help? Thanks!
I found a soulotion. I added this to my spec:
{
"operation": "shift",
"spec": {
"vertragsdetails": {
"versichertePersonen": {
"versicherungssummenOderLeistungen": {
"*": {
"kennung": {
"#1": "vertragsdetails.versichertePersonen.versicherungssummenOderLeistungen[]"
}
}
}
"dataToKeep": "vertragsdetails.versichertePersonen.dataToKeep"
}
}
}
}

Array mapping with JOLT

First time JOLT user trying to restructure an array into a similar multi-level array. stackoverflow is asking for less code and more words, so I hope this extra sentence covers that.
Input JSON
{
"studentIdentifier": "453089029",
"studentRegistrationNumber": "753082022",
"parentIdentifier": "1001142760",
"parentFamilyName": "lastname1001142760",
"relationshipIdentifier": "1001142762",
"relationshipToStudent": "Mother"
},
{
"studentIdentifier": "453089193",
"studentRegistrationNumber": "753082123",
"parentIdentifier": "1001142760",
"parentFamilyName": "lastname1001142760",
"relationshipIdentifier": "1001159585",
"relationshipToStudent": "Mother"
}
]
Desired JSON output
{
"carer" : {
"relationships" : [ {
"relationshipIdentifier" : "1001142762",
"relationshipToStudent" : "Mother",
"student" : {
"studentIdentifier" : "453089029",
"studentRegistrationNumber" : "753082022"
}
}, {
"relationshipIdentifier" : "1001159585",
"relationshipToStudent" : "Mother",
"student" : {
"studentIdentifier" : "453089193",
"studentRegistrationNumber" : "753082123"
}
} ],
"parentIdentifier" : "1001142760",
"parentFamilyName" : "lastname1001142760"
}
}
JOLT spec so far
[
{
"operation": "shift",
"spec": {
"*": {
"#": "carer.relationships[].student",
"parent*": "carer.&"
}
}
},
{
"operation": "cardinality",
"spec": {
"*": {
"parent*": "ONE"
}
}
},
{
"operation": "remove",
"spec": {
"carer": {
"relationships": {
"*": {
"student": {
"parent*": "",
"relationship*": ""
}
}
}
}
}
}
]
Currently getting this result
{
"carer" : {
"relationships" : [ {
"student" : {
"studentIdentifier" : "453089029",
"studentRegistrationNumber" : "753082022"
}
}, {
"student" : {
"studentIdentifier" : "453089193",
"studentRegistrationNumber" : "753082123"
}
} ],
"parentIdentifier" : "1001142760",
"parentFamilyName" : "lastname1001142760"
}
}
How to map the missing relationship* fields at the right level or is there a better approach?
Spec:
[
{
"operation": "shift",
"spec": {
"*": {
"*": "&",
"student*": "carer.relationships[&1].student.&",
"relationship*": "carer.relationships[&1].&"
}
}
},
{
"operation": "cardinality",
"spec": {
"parent*": "ONE"
}
}
]

Jolt spec file multiple array of element

I am trying to write a jolt transformation for the input below:
Input
[{
"factValues": [
{
uniqeid:"1",
"values":"1234567"
},
{
uniqeid:"1",
"teams":"abcde"
}]
},{
"factValues": [
{
uniqeid:"2",
"values":"6758595"
},
{
uniqeid:"2",
"teams":"medrgeh"
}]
}
]
Excepted Output.
{
"factValues": [{
uniqeid:"1",
"values":'1234567',
"teams":'76599876'
},
{
uniqeid:"2",
"values":'6758595',
"teams":'medrgeh'
}
]
}
Kindly help me to achieve the expected output.json in spec.json. The spec is not transforming as expected output. I want learn how to use attributes inside the string parser
Shifted all the values to the factValues. Then selected the first element from the uniqueid array,
[
{
"operation": "shift",
"spec": {
"*": {
"*": {
"*": {
"uniqeid": "factValues.[&3].uniqeid",
"values": "factValues.[&3].values",
"teams": "factValues.[&3].teams"
}
}
}
}
}, {
"operation": "modify-overwrite-beta",
"spec": {
"*": {
"*": {
"uniqeid": "=firstElement(#(1,uniqeid))"
}
}
}
}
]

JsonTransformation using Jolt

I'm using jolt + java(https://github.com/bazaarvoice/jolt) to transform an external JSON in a format that I can understand.
My problem is the structure keeps changing and this is making my spec more and more complex.
I want to extract all the fields which are called "path" no matter the structure.
does someone have an idea how can I do that?
Example of structure:
{
"groups": {
"rows": {
"fieldSets": {
"fields": [{
"path": "example"
}]
}
}
}
}
or
{
"groups": {
"rows": {
"rowsets": {
"fieldSets": {
"fields": [{
"path": "example"
}]
}
}
}
}
}
or
{
"groups": {
"fieldSets": {
"fields": [{
"path": "example"
}]
}
}
}
in the end, I just want an array with plain "path" values.
I am also new to the JOLT. Anyway I tried with what I understood from your question. Just try the below spec:
[
{
"operation": "shift",
"spec": {
"groups": {
"rows": {
"fieldSets": {
"fields": {
"*": {
"path": "path"
}
}
}
}
}
}
}
]
If it is not what you are expecting, then please give an output json, so that i can understood what you want.

Jolt transformation json to json for two siftr operations

I am trying to map one a value of input json to a hashmap of the output json and also want to save the value to some another key using jolt json transformation
input json:
{
"metadata": "/a=value1/b=value2/c=value3"
}
spec:
[{
"operation": "shift",
"spec": {
"metadata": {
// match exactly sets of key value pairs
"/*/*/*": {
// pull each one off and accumulate them into a temp array
"$(0,1)": "temp[]",
"$(0,2)": "temp[]",
"$(0,3)": "temp[]"
}
}
}
},
{
"operation": "shift",
"spec": {
"temp": {
"*": {
// match each item by ":" into two captures
"*=*": {
"$(0,2)": "data.&(1,1)"
}
}
}
}
}
]
output
{
"data" : {
"a" : "value1",
"b" : "value2",
"c" : "value3"
}
}
whereas I also want to map the string metadata to originalData
Expected Output:
{
"data" : {
"a" : "value1",
"b" : "value2",
"c" : "value3"
},
"originalData":"/a=value1/b=value2/c=value3"
}
Spec
[
{
"operation": "shift",
"spec": {
"metadata": {
"#": "originalData",
// match exactly sets of key value pairs
"/*/*/*": {
// pull each one off and accumulate them into a temp array
"$(0,1)": "temp[]",
"$(0,2)": "temp[]",
"$(0,3)": "temp[]"
}
}
}
},
{
"operation": "shift",
"spec": {
"originalData": "originalData", // passthru
"temp": {
"*": {
// match each item by ":" into two captures
"*=*": {
"$(0,2)": "data.&(1,1)"
}
}
}
}
}
]
[
{
"operation": "modify-overwrite-beta",
"spec": {
"metadata": "=split('/',#(1,metadata))"
}
},
{
"operation": "shift",
"spec": {
"metadata": {
"*": {
"*=*": {
"$(0,2)": "data.&(1,1)"
}
}
}
}
}
]