JOLT Transformation with Arrays - jolt

Looking for help on Jolt transformation below
{
"consents": [
{
"consent-data": [
{
"consent-key": "DOB",
"consent-value": "02/2006"
}
],
"consent-id": "123",
"consent-indicator": "true",
"consent-type": "COPPA",
"resource-id": "456"
},
{
"consent-data": [
{
"consent-key": "DOB",
"consent-value": "02/2006"
}
],
"consent-id": "567",
"consent-indicator": "true",
"consent-type": "COPPA",
"resource-id": "678"
}
]
}
Expected Output :
{
"Consents": [
{
"consentDataResponse": [
{
"consentKey": "DOB",
"consentValue": "02/2006"
}
],
"consentId": "123",
"consentIndicator": "true",
"consentType": "COPPA",
"resourceId": "456"
},
{
"consentDataResponse": [
{
"consentKey": "DOB",
"consentValue": "02/2006"
}
],
"consentId": "567",
"consentIndicator": "true",
"consentType": "COPPA",
"resourceId": "678"
}
]
}
Trasformation iam using :
[
{
"operation": "shift",
"spec": {
"consents": {
"*": {
"consent-id": "consents[&1].retailerId",
"consent-indicator": "consents[&1].consentIndicator",
"consent-type": "consents[&1].consentType",
"resource-id": "consents[&1].resoureId",
"consent-data": {
// loop thru the orderItems array
"*": {
"consent-key": "consentDataResponse[&1].consentKey",
"consent-value": "consentDataResponse[&1].consentValue"
}
}
}
}
}
}
]
Current output :
{
"consentDataResponse" : [ {
"consentKey" : [ "DOB", "DOB1" ],
"consentValue" : [ "02/2006", "03/2006" ]
} ],
"consents" : [ {
"consentIndicator" : "true",
"consentType" : "COPPA",
"resoureId" : "22=",
"retailerId" : "11="
}, {
"consentIndicator" : "false",
"consentType" : "COPPA1",
"resoureId" : "44=",
"retailerId" : "33="
} ]
}
Note - Here, consents and consentDataResponse will be repeated, currently I am getting consentDataResponse as a separate object with consolidated values but it should be per consents. Could you please help me here

[
{
"operation": "shift",
"spec": {
"consents": {
"*": {
"consent-data": {
"*": {
"consent-key": "Consents[&3].consentDataResponse[&1].consentKey",
"consent-value": "Consents[&3].consentDataResponse[&1].consentValue"
}
},
"consent-id": "Consents[&1].consentId",
"consent-indicator": "Consents[&1].consentIndicator",
"consent-type": "Consents[&1].consentType",
"resource-id": "Consents[&1].resourceId"
}
}
}
}
]
You did almost correct and just added indexing inside the consent-data loop.

Related

JoltTransform convert to string

I am strugling a bit with my JoltTransform. I just need to convert the decimal characters to string, but for the life of me I cannot get it to work, as per the example it would be the policy_revision_no and the policy_endorsement_no ..
My example json file I am using is:
{
"policy_unique_reference": "TST1",
"item_unique_reference": "TST2",
"item_parent_item_unique_reference": "",
"item_type": "Cover",
"item_parent_section": "Stuff",
"item_subsection_extension": "",
"policy_revision_no": 1,
"policy_endorsement_no": 2
}
My current Jolt Transform is:
[
{
"operation": "shift",
"spec": {
"*": "Items.&"
}
},
{
"operation": "modify-overwrite-beta",
"spec": {
"*": {
"Items": {
"policy_revision_no": "=toString"
}
}
}
}
]
My current result that I am getting is:
{
"Items" : {
"policy_unique_reference" : "TST1",
"item_unique_reference" : "TST2",
"item_parent_item_unique_reference" : "",
"item_type" : "Cover",
"item_parent_section" : "Stuff",
"item_subsection_extension" : "",
"policy_revision_no" : 1,
"policy_endorsement_no" : 2,
"Items" : { }
}
}
Thank you.
You can directly apply modify transform such as
[
{
"operation": "modify-overwrite-beta",
"spec": {
"policy_*": "=toString"
}
}
]
presumingly you need to apply for the elements with keys starting with policy_

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

Expected [START_OBJECT] under [filter]

I want to put double filter in aggs.
such like this.
"aggs": {
"download1" : {
"filter" : [
{ "term": { "IPV4_DST_ADDR":"192.168.0.159"}},
{ "range": { "LAST_SWITCHED": { "gte": "now-5m" } }}
],
"aggs" : {
"downlod_bytes" : { "sum" : { "field" : "IN_BYTES" } }
}
}
}
but it show me an error:
"error": {
"root_cause": [
{
"type": "parsing_exception",
"reason": "Expected [START_OBJECT] under [filter], but got a [START_ARRAY] in [download1]",
"line": 33,
"col": 24
}
]}
How can I do, thank you in advance!
You need to combine both queries with a bool/filter
{
"aggs": {
"download1": {
"filter": {
"bool": {
"filter": [
{
"term": {
"IPV4_DST_ADDR": "192.168.0.159"
}
},
{
"range": {
"LAST_SWITCHED": {
"gte": "now-5m"
}
}
}
]
}
},
"aggs": {
"downlod_bytes": {
"sum": {
"field": "IN_BYTES"
}
}
}
}
}
}

Simplifying Google Sheet JSON using Jolt

I have gone through most of the test cases in Jolt that seem to serve as examples, but cannot find anything that does what I am looking for. For background, the source code is a stripped version of what comes from a google sheet. So rows and columns.
Source JSON:
[
{
"values": [
{
"formattedValue": "ACHME - Thailand"
},
{
"formattedValue": "5,368.11"
},
{
"formattedValue": "17.09%"
}
]
},
{
"values": [
{
"formattedValue": "ACHME-B2A"
},
{
"formattedValue": "101.47"
},
{
"formattedValue": "0.32%"
}
]
},
{
"values": [
{
"formattedValue": "ACHME-B2E"
},
{
"formattedValue": "83.79"
},
{
"formattedValue": "0.27%"
}
]
}
]
Desired Output:
[
{
"row": [
"ACHME - Thailand",
"5,368.11",
"17.09%"
]
},
{
"row": [
"ACHME-B2A",
"101.47",
"0.32%"
]
},
{
"row": [
"ACHME-B2E",
"83.79"
"0.27%"
]
}
]
I have tried this Jolt that gets me most of the way there, but I am still losing the row boundaries. It all comes out with one 'row' element and all of the values in an array.
[
{
"operation": "shift",
"spec": {
"*": {
"values": {
"*": {
"formattedValue": "row[]"
}
}
}
}
}
]
Spec
[
{
"operation": "shift",
"spec": {
"*": { // row index
"values": {
"*": { // column index
"formattedValue": "[&3].row[&1]"
}
}
}
}
}
]
Note, this assumes that all the incoming "values" arrays are the same length.